//
// Framework 0.98
//
// Copyright 2010, Licensed under the MIT license.
// http://innovator.samsungmobile.com/
//
//

/* @Framework_Ver 0.98 */


// Basic Cheese Object Component
var CheeseBasic = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "object";
}



// Cheese Button Component
var CheeseButton = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "button";
}

CheeseButton.prototype.option = function ( _data )
{
	for ( var k in _data)
	{


		if(k == "fontSize"){
			if (_data[k] == "big"){
				Cheese(this).css("font-size","32px");
			} else if (_data[k] == "normal"){
				Cheese(this).css("font-size","28px");
			} else if (_data[k] == "small"){
				Cheese(this).css("font-size","24px");
			} else {
				Cheese(this).css("font-size",_data[k]);
			}
		}

		if(k == "fontColor"){
			Cheese(this).css("color",_data[k]);
		}



		if(k == "btnImage"){
			Cheese(this).css("-webkit-border-image" ,"url('"+_data[k]+"') 15 stretch stretch");
		}


	}
}



// Cheese RssTime Component
var CheeseRSSTime = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "rssTime";
}

CheeseRSSTime.prototype.option = function ( _data )
{
	for ( var k in _data)
	{
		if(k == "background"){
			if (_data[k][0] == "color"){
				Cheese(this).css("background",_data[k][1]);
			}

			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				} else {
					Cheese(this).addClass("c_"+_data[k][1]);
				}
			}
		}

		if(k == "fontSize"){
			if (_data[k] == "big"){
				Cheese(this).css("font-size","24px");
			} else if (_data[k] == "normal"){
				Cheese(this).css("font-size","18px");
			} else if (_data[k] == "small"){
				Cheese(this).css("font-size","14px");
			} else {
				Cheese(this).css("font-size",_data[k]);
			}
		}

		if(k == "fontColor"){
			Cheese(this).css("color",_data[k]);
		}

	}
}





// Cheese Scene Component
var CheeseScene = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "scene";
}

CheeseScene.prototype.option = function ( _data )
{
	for ( var k in _data)
	{
		if(k == "backgroundImage"){
			if (_data[k] == "image1"){
				Cheese(this).children('.sceneBackground').addClass('image1');
			} else if (_data[k] == "image2"){
				Cheese(this).children('.sceneBackground').addClass('image2');
			} else if (_data[k] == "image3"){
				Cheese(this).children('.sceneBackground').addClass('image3');
			} else if (_data[k] == "image4"){
				Cheese(this).children('.sceneBackground').addClass('image4');
			} else if (_data[k] == "none"){
				Cheese(this).children('.sceneBackground').css("background-image","none");
			} else {
				Cheese(this).children('.sceneBackground').css("background-image","url("+_data[k]+")");
			}
		}

		if(k == "opacity"){
			Cheese(this).children('.sceneBackground').css("opacity",_data[k]);
		}

		if(k == "backgroundColor"){
			Cheese(this).css("backgroundColor",_data[k]);
		}

		if(k == "softkeyData" ) {
			Cheese(this).buffer("CheeseSceneComponentDataSoftkey", _data[k] );
		}
	}
}

CheeseScene.prototype.set = function ()
{
	var cheeseThis = Cheese(this);
	cheeseThis.children().wrapAll("<div class='sceneWrap'></div>"); // Blank DIV Element for BackgroundImage
	cheeseThis.prepend("<div class='frameTop'></div><div class='frameBottom'></div><div class='sceneBackground'></div>"); // Blank DIV Element for BackgroundImage

}




// Cheese popup Component
var CheesePopup = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "popup";
}

CheesePopup.prototype.option = function ( _data )
{
	for ( var k in _data)
	{
		if(k == "background"){
			if (_data[k][0] == "color"){
				Cheese(this).find('.popCon').css("background",_data[k][1]);
			}

			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).find('.popCon').css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				} else {
					Cheese(this).find('.popCon').addClass("c_"+_data[k][1]);
				}
			}
		}
		if(k == "fontColor"){
			Cheese(this).find('.popCon').css("color",_data[k]);
		}
		if(k == "borderColor"){
			Cheese(this).find('.popCon').css("border-color",_data[k]);
		}
		if(k == "fontSize"){
			if (_data[k] == "big"){
				Cheese(this).css("font-size","28px");
			} else if (_data[k] == "normal"){
				Cheese(this).css("font-size","24px");
			} else if (_data[k] == "small"){
				Cheese(this).css("font-size","20px");
			} else {
				Cheese(this).css("font-size",_data[k]);
			}
		}
		if(k == "btnAreaBackground"){
			if (_data[k][0] == "color"){
				Cheese(this).find('.popCon .btnArea').css("background",_data[k][1]);
			}

			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).find('.popCon .btnArea').css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				} else {
					Cheese(this).find('.popCon .btnArea').addClass("c_"+_data[k][1]);
				}
			}
		}
	}

}

CheesePopup.prototype.set = function ( )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheesePopupComponentDataSet");
	if ( !dataSet )
		cheeseThis.buffer("CheesePopupComponentDataSet", dataSet = {} );

	cheeseThis.contents().not(".btnArea").wrapAll('<div class="popConTxt"></div>');
	cheeseThis.contents().wrapAll('<div class="popCon"></div>');
	if ( typeof dataSet.okFunc == "function" ) cheeseThis.children('.popCon').children('.btnArea').children(".popupOK").tap( dataSet.okFunc );
	if ( typeof dataSet.cancelFunc == "function" ) cheeseThis.children('.popCon').children('.btnArea').children(".popupCancel").tap( dataSet.cancelFunc );
	cheeseThis.find('.btn').touchStart(function(){ Cheese(this).addClass("focus")})
				.touchEnd(function(){ Cheese(this).removeClass("focus")})

}

CheesePopup.prototype.data = function ( _data )
{
	var cheeseThis = Cheese(this),
		dataSet = {},
		inHTML = "",
		btnHTML = "";
	for( var k in _data )
	{
		if( k == "html" )
			dataSet.html = _data[k];
		else if( k =="okFunc")
			dataSet.okFunc = _data[k];
		else if( k =="cancelFunc" )
			dataSet.cancelFunc = _data[k];
	}
	inHTML += dataSet.html;
	if( dataSet.okFunc )
		btnHTML += '<button class="btn popupOff popupOK">OK</button> ';
	if( dataSet.cancelFunc )
		btnHTML += ' <button class="btn popupOff popupCancel">Cancel</button>';
 	if ( btnHTML != "" ) inHTML += '<div class="btnArea">' + btnHTML + '</div>';

 	cheeseThis.buffer("CheesePopupComponentDataSet", dataSet);
	cheeseThis.html(inHTML);
 	cheeseThis.set();
}






//  Page Control Component
var CheesePageControl = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type="pageControl";
}

CheesePageControl.prototype.option = function ( _data )
{
	for ( var k in _data)
	{
		if(k == "fontColor"){
			Cheese(this).find('li').css("color",_data[k]);
		}

		if(k == "glow"){
			if (_data[k] == "true"){
				Cheese(this).find('.glow').show();
			} else if (_data[k] == "false"){
				Cheese(this).find('.glow').hide();
			}
		}

		if(k == "fontSize"){
			if (_data[k] == "big"){
				Cheese(this).find('li').css("font-size","34px");
			} else if (_data[k] == "normal"){
				Cheese(this).find('li').css("font-size","30px");
			} else if (_data[k] == "small"){
				Cheese(this).find('li').css("font-size","26px");
			} else {
				Cheese(this).find('li').css("font-size",_data[k]);
			}
		}

		if(k == "background"){
			if (_data[k][0] == "color"){
				Cheese(this).css("background",_data[k][1]);
			}
			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				} else {
					Cheese(this).addClass("c_"+_data[k][1]);
				}
			}
		}

		if(k == "backgroundImage"){
			Cheese(this).css("background-image","url("+_data[k]+")");
		}

		if( k == "transOption" )
		{
			Cheese(this).buffer("CheesePageControlComponentDataTransOption", _data[k] );
		}
	}
}

CheesePageControl.prototype.data = function ( _data )
{
	var cheeseThis = Cheese(this);
	if( !_data )
		return cheeseThis.buffer("CheesePageControlComponentDataSet");

	var inHTML = "<ul>",
		dataSet = new Array(),
		dataSub = "<div class='subScene'>"+ _data[0] +"</div>";

	cheeseThis.buffer("CheesePageControlComponentDataSub", dataSub );
	for ( var k in _data[1] )
	{
		var dataSetCur = {};
		dataSetCur.key = k;
		if ( typeof _data[1][k] == "function" )
			dataSetCur.viewFunc = _data[1][k];
		else if( typeof _data[1] == "object" )
		{
			dataSetCur.viewFunc = _data[1][k][0];
			dataSetCur.func = _data[1][k][1];
		}
		dataSetCur.enable = true;

		dataSet.push(dataSetCur);

		inHTML += "<li>"+dataSetCur.key+"</li>";
	}

	inHTML += "</ul>";
	cheeseThis.buffer("CheesePageControlComponentDataSet", dataSet );
	cheeseThis.buffer("CheesePageControlComponentDataCurPage", null);
	cheeseThis.html(inHTML);
	cheeseThis.after(dataSub);
	cheeseThis.set();
}

CheesePageControl.prototype.count = function ()
{
	return Cheese(this).children('ul').children('li').size();
}

CheesePageControl.prototype.set = function ()
{
	var cheeseThis = Cheese(this);
	cheeseThis.prepend("<div class='glow'></div>" + 										// Blank DIV Element for Glow
						"<span class='arrLeft'></span><span class='arrRight'></span>"); 	// Blank DIV Element for Arrow Icon

	if ( !cheeseThis.buffer("CheesePageControlComponentDataSet") )
	{
		cheeseThis.buffer("CheesePageControlComponentDataSub", cheeseThis.sub().outerHTML() );
		cheeseThis.buffer("CheesePageControlComponentDataSet", new Array() );
		cheeseThis.children('ul').children('li').each ( function () {
			var cheeseThis = Cheese(this),
				dataSet = cheeseThis.parent().parent().buffer("CheesePageControlComponentDataSet"),
				dataSetCur = {};

			dataSetCur.key = Cheese.trim( cheeseThis.text() );
			dataSetCur.enable = true;
			dataSet.push( dataSetCur );
		});
	}

	cheeseThis.children('ul').addClass('pageList');
	var dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet"),
		dataSub = cheeseThis.buffer("CheesePageControlComponentDataSub");
	for( var i = 1, l = dataSet.length; i < l; i++ )
		cheeseThis.after( dataSub );

	cheeseThis.children('.pageList').flickLeft(function(){
		Cheese(this).siblings(".arrLeft").trigger( CheeseGlobal.EVENTSTRING.TAP );
	}).flickRight(function(){
		Cheese(this).siblings(".arrRight").trigger( CheeseGlobal.EVENTSTRING.TAP );
	});

	cheeseThis.children('.arrLeft').tap(function(){
		Cheese(this).parent().go("left");
	});

	cheeseThis.children('.arrRight').tap(function(){
		Cheese(this).parent().go("right");
	});

	cheeseThis.go(0);
}

CheesePageControl.prototype.rss = function ( _data, _tagOpts, _opts, _toXmlSuccessCallBackSet )
{
	if( arguments.length == 1 && typeof arguments[0] == "object" )
	{
		var args = arguments[0];
		_data = args[0];
		_tagOpts = args[1];
		_opts = args[2];
		_toXmlSuccessCallBackSet = args[3];
	};

	if ( typeof _data == "object" )
	{
		//h pageControl이 로드될 때랑 해당 page 로 이동할 때 호출할 함수 저장
		var funcSet = new Array(),
		//h rss 관련 옵션 데이터 저장 ( page 이동시 사용)
			dataSetRSS = new Array();

		for( var k in _data )
		{
			funcSet[k] = [function ( idx ){
							var cheeseThis = Cheese(this),
								cheeseThisDataSetRSS = cheeseThis.buffer("CheesePageControlComponentDataSetRSS");

							cheeseThis.sub(idx).find(".list").rss(
								cheeseThisDataSetRSS[ idx ].url,
								( cheeseThisDataSetRSS[idx].tagOpts ) ?
									cheeseThisDataSetRSS[idx].tagOpts :
									cheeseThis.buffer("CheesePageControlComponentDataRSSTagOpts"),
								( cheeseThisDataSetRSS[idx].opts ) ?
									cheeseThisDataSetRSS[idx].opts :
									cheeseThis.buffer("CheesePageControlComponentDataRSSOpts"),
								( cheeseThisDataSetRSS[idx].xmlSuccessCallBackSet ) ?
									cheeseThisDataSetRSS[idx].xmlSuccessCallBackSet :
									cheeseThis.buffer("CheesePageControlComponentDataRSSXmlSuccessCallBackSet")
							);
						},
						function ( idx ) {
							//h 페이지가 이동되면 컴포넌트 하단 부분에 업데이트 시간 표시
							Cheese.rssTime( Cheese(this).sub(idx).find('.list').buffer("CheeseListComponentDataRSSTime") );
						}
					];

			var dataSetRSSCur = {};
			dataSetRSSCur.url = (typeof _data[k] == "object")?_data[k][0]:_data[k];
			dataSetRSSCur.tagOpts = (typeof _data[k] == "object")?_data[k][1]:null;
			dataSetRSSCur.opts = (typeof _data[k] == "object")?_data[k][2]:null;
			dataSetRSSCur.xmlSuccessCallBackSet = (typeof _data[k] == "object")?_data[k][3]:null;
			dataSetRSS.push(dataSetRSSCur);
		}

		var dataSet =  [ "<div class='list'></div>", funcSet ];
		Cheese(this).buffer("CheesePageControlComponentDataSet", dataSet )
					.buffer("CheesePageControlComponentDataSetRSS", dataSetRSS)
					.buffer("CheesePageControlComponentDataRSSTagOpts", _tagOpts)
					.buffer("CheesePageControlComponentDataRSSOpts", _opts)
					.buffer("CheesePageControlComponentDataRSSXmlSuccessCallBackSet", _toXmlSuccessCallBackSet )
					.data( dataSet );
	};
}

CheesePageControl.prototype.go = function ( _page, _opts )
{
	if (typeof _page == "number")
	{
		var cheeseThis = Cheese(this),
			dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet"),
			curPage = cheeseThis.buffer("CheesePageControlComponentDataCurPage"),
			subScene = cheeseThis.siblings('.subScene'),
			pageList = cheeseThis.children('ul').children('li');

		if(  curPage === _page )
			return;

		if( !dataSet )
			cheeseThis.buffer("CheesePageControlComponentDataSet", dataSet = new Array() );

		pageList.removeClass('cur');
		pageList.eq(_page).addClass('cur');

		cheeseThis.buffer("CheesePageControlComponentDataCurPage", _page);

		if ( dataSet[_page] )
		{
			dataSet[_page].enable = true;

			if ( !dataSet[_page].viewCheck && dataSet[_page].viewFunc )
			{

				dataSet[_page].viewFunc.call( this, _page );
				dataSet[_page].viewCheck = true;
			}

			if ( dataSet[_page].func )
				dataSet[_page].func.call( this, _page );
		}

		if( typeof curPage != "number")
		{
			subScene.hide();
			subScene.eq(_page).show();
		}
		else
		{
			Cheese.transition(
				subScene.eq(_page),
				subScene.eq(curPage), (_opts)?_opts: cheeseThis.buffer("CheesePageControlComponentDataTransOption") );
		}
	}
	else if( typeof _page == "string" )
	{
		var cheeseThis = Cheese(this),
			curPage = cheeseThis.buffer("CheesePageControlComponentDataCurPage"),
			pageSize = cheeseThis.children('ul').children('li').size(),
			dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet");

		var opts = {};
		_opts = (_opts)?_opts: cheeseThis.buffer("CheesePageControlComponentDataTransOption");
		for( var k in _opts )
			opts[k] = _opts[k];

		if( _page == "left" )
		{
			opts.transDirection = "on";
			var nextPage = (curPage-1+pageSize)%pageSize;
			while ( dataSet[nextPage] && !dataSet[nextPage].enable )
				nextPage = (nextPage-1+pageSize)%pageSize;
			cheeseThis.go( nextPage, opts );
		}
		else if ( _page == "right" )
		{
			opts.transDirection = "off";
			var nextPage = (curPage+1)%pageSize;
			while ( dataSet[nextPage] && !dataSet[nextPage].enable )
				nextPage = (nextPage+1)%pageSize;
			cheeseThis.go( nextPage, opts );
		}
	}
}

CheesePageControl.prototype.sub = function ( _idx )
{
	var cheeseThis= Cheese(this),
		idx = ( typeof _idx == "undefined" )? cheeseThis.buffer("CheesePageControlComponentDataCurPage") : _idx ;
	return cheeseThis.siblings(".subScene").eq( idx );
}

CheesePageControl.prototype.addPage = function ( _data )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet"),
		dataSetSize = dataSet.length,
		dataSub = cheeseThis.buffer("CheesePageControlComponentDataSub"),
		inHTML ="";

	for ( var k in _data )
	{
		var dataSetCur = {};
		dataSetCur.key = k;
		dataSetCur.enable = true;
		if ( typeof _data[k] == "function" )
			dataSetCur.viewFunc = _data[k];
		else if( typeof _data[1] == "object" )
		{
			dataSetCur.viewFunc = _data[k][0];
			dataSetCur.func = _data[k][1];
		}
		dataSet.push(dataSetCur);

		inHTML += "<li>"+dataSetCur.key+"</li>";
	}

	cheeseThis.children('ul.pageList').append(inHTML);
	for( var i = dataSetSize, l = dataSet.length; i < l; i++ )
		cheeseThis.sub(i-1).after( dataSub );
}

CheesePageControl.prototype.func = function ( _data )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet");
	if( !dataSet )
		cheeseThis.buffer("CheesePageControlComponentDataSet", dataSet = new Array() );

	if( typeof _data == "object" )
		for ( var k in _data)
			dataSet[k].func = _data[k];
}

CheesePageControl.prototype.enablePage = function ( _page )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet");
	if( !dataSet )
		cheeseThis.buffer("CheesePageControlComponentDataSet", dataSet = new Array() );

	dataSet[_page].enable = true;
}

CheesePageControl.prototype.disablePage = function ( _page )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet");
	if( !dataSet )
		cheeseThis.buffer("CheesePageControlComponentDataSet", dataSet = new Array() );

	dataSet[_page].enable = false;
}

CheesePageControl.prototype.viewFunc = function ( _data )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet");
	if( !dataSet )
		cheeseThis.buffer("CheesePageControlComponentDataSet", dataSet = new Array() );

	if( typeof _data == "object" )
		for ( var k in _data)
		{
			dataSet[k].viewFunc = _data[k];
			dataSet[k].viewCheck = false;
		}
}

CheesePageControl.prototype.refresh = function ()
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet"),
		curPage = cheeseThis.buffer("CheesePageControlComponentDataCurPage");

	if ( dataSet && dataSet[curPage] )
	{
		if ( dataSet[curPage].viewFunc )
		{
			dataSet[curPage].viewFunc.call( this, curPage );
			dataSet[curPage].viewCheck = true;
		}

		if ( dataSet[curPage].func )
			dataSet[curPage].func.call( this, curPage );
	}
}

CheesePageControl.prototype.autoRefresh = function ( _time )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheesePageControlComponentDataSet");

	if( dataSet && typeof dataSet.timer == "number" )
	{
		Cheese.timer( dataSet.timer );
		dataSet.timer = null;
	}

	if( !_time || _time <= 0 )
		return;

	dataSet.timer = Cheese.timer( function() {
		cheeseThis.refresh();
	}, _time );
}





// Cheese list Component
var CheeseList = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type="list";
}

CheeseList.prototype.option = function ( _data )
{
	for ( var k in _data)
	{
		if(k == "glow"){
			if (_data[k] == "true"){
				Cheese(this).find('ul > li > .glow').show();
			} else if (_data[k] == "false"){
				Cheese(this).find('ul > li > .glow').hide();
			}
		}


		if(k == "lineTopColor"){
			Cheese(this).find('ul > li .listLineTop').css('display','block');
			Cheese(this).find('ul > li .listLineTop').css('border-color',_data[k]);
		}

		if(k == "lineBottomColor"){
			Cheese(this).find('ul > li .listLineBottom').css('display','block');
			Cheese(this).find('ul > li .listLineBottom').css('border-color',_data[k]);
		}

		if(k == "lineTopOpacity"){
			Cheese(this).find('ul > li .listLineTop').css('opacity',_data[k]);
		}

		if(k == "lineBottomOpacity"){
			Cheese(this).find('ul > li .listLineBottom').css('opacity',_data[k]);
		}



		if(k == "fontColor"){
			Cheese(this).find('ul > li').css("color",_data[k]);
		}

		if(k == "subFontColor"){
			Cheese(this).find('ul > li .subTxt').css("color",_data[k]);
		}

		if(k == "background"){
			if (_data[k][0] == "color"){
				Cheese(this).find("li").css("background",_data[k][1]);
			}

			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).find("li").css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				} else {
					Cheese(this).find("li").addClass("c_"+_data[k][1]);
				}
			}
		}

		if(k == "maxLen")
		{
			Cheese(this).buffer("CheeseListComponentDataMaxLen", _data[k]);
			Cheese(this).data( Cheese(this).buffer("CheeseListComponentDataInput") );
		}

		if(k == "comPosition")
		{
			Cheese('.innerCom').css('float',_data[k]);
		}
	}
}

CheeseList.prototype.data = function ( _data )
{
	var cheeseThis = Cheese(this);
	if( !_data )
		return cheeseThis.buffer("CheeseListComponentDataSet");

	var inHTML = "<ul>",
		dataSet = new Array();

	// save data
	for( var k in _data )
	{
		var dataSetCur = {},
			i = 0;

		dataSetCur.key = k;
		dataSetCur.type = _data[k][i++];

		if( dataSetCur.type == "img" || dataSetCur.type == "img2" )
			dataSetCur.img = _data[k][i++];
		else if( typeof _data[k][i] == "boolean" )
			dataSetCur.select =_data[k][i++];

		dataSetCur.title = _data[k][i++];

		if( typeof _data[k][i] == "string" )
			dataSetCur.subTitle = _data[k][i++];
		if( typeof _data[k][i] == "function" )
			dataSetCur.func = _data[k][i++];
		if( typeof _data[k][i] == "object" && typeof _data[k][i][0] == "function" )
		{
			dataSetCur.funcArgs = new Array();
			for(var j = 1, l = _data[k][i].length; j<l; j++ )
				dataSetCur.funcArgs.push( _data[k][i][j] );

			dataSetCur.func = _data[k][i++][0];
		}


		if ( dataSetCur.type == "accordion" )
			dataSetCur.sub = _data[k][i];

		dataSet.push(dataSetCur);


		var titleLen = cheeseThis.buffer("CheeseListComponentDataTitleLen"),
			subLen = cheeseThis.buffer("CheeseListComponentDataSubLen"),
			reduceTitle = ( titleLen )? Cheese.reduceString(dataSetCur.title, titleLen): dataSetCur.title,
			reduceSub = ( subLen )? Cheese.reduceString(dataSetCur.subTitle, subLen): dataSetCur.subTitle;

												inHTML += '<li' + ((dataSetCur.type=="radio" || dataSetCur.type=="check" || dataSetCur.type=="onoff" || dataSetCur.type=='accordion')?' class="'+ dataSetCur.type+'"':'') + '>';
		if( dataSetCur.img )
			if(dataSetCur.type=="img") 			inHTML += '<div class="img"><img src="' + dataSetCur.img + '"></div>' + '<div class="txt">' + reduceTitle + '</div>';
			else 								inHTML += '<div class="txt">' + reduceTitle + '</div>' + '<div class="img"><img src="' + dataSetCur.img + '"></div>';
		else if(dataSetCur.type == "accordion")	inHTML += reduceTitle;
		else 									inHTML += '<div class="txt">' + reduceTitle + '</div>';

		if( dataSetCur.subTitle ) 				inHTML += '<div class="subTxt">' + reduceSub + '</div>';
		if( dataSetCur.type == "accordion" )	inHTML += '<div class="accCon"><div class="list"></div></div>'
												inHTML += '</li>';

	}
	inHTML += "</ul>";

	cheeseThis.buffer("CheeseListComponentDataSet", dataSet );

	cheeseThis.html(inHTML);
	cheeseThis.children('ul').children('li.accordion').children('.accCon').children('.list').each( function() {
		var cheeseThis = Cheese(this),
			li = cheeseThis.parent().parent(),
			dataSet = li.parent().parent().buffer("CheeseListComponentDataSet"),
			idx = li.index();


		cheeseThis.data(dataSet[ idx ].sub);
	});

	cheeseThis.set();
}

CheeseList.prototype.count = function ()
{
	return Cheese(this).children('ul').children('li').size();
}

CheeseList.prototype.set = function ( )
{
	// List Component Default Setting
	var cheeseThis = Cheese(this),
		listRow = cheeseThis.children('ul').children('li');

	listRow.prepend("<div class='listLineTop'></div>"+		// Blank DIV Element for LineTop
					"<div class='listLineBottom'></div>"+		// Blank DIV Element for LineBottom
					"<div class='glow'></div>"); 		// Blank DIV Element for Gradient

	listRow.not('.accordion').touchStart(	function() { Cheese(this).addClass('focus'); })
							.touchEnd(		function() { Cheese(this).removeClass('focus'); });

	listRow.each( function() {

		var cheeseThis = Cheese(this);
		cheeseThis.children('.subTxt').parent().addClass("multiLine"); //add multiline class

		//h add img class - 타입에 따라 두가지로 된다.
		if( cheeseThis.children('.img').size() != "0")
		{
			cheeseThis.addClass("img");
			if( !cheeseThis.children('.img').next().hasClass('txt') )
				cheeseThis.addClass("img2");
		};
	});

	//h 만약 데이터가 없다면 마크업 상에 데이터들을 읽어들여 저장
	if( !cheeseThis.buffer("CheeseListComponentDataSet") )
	{

		cheeseThis.buffer("CheeseListComponentDataSet", new Array() );
		listRow.each ( function () {
			var cheeseThis = Cheese(this),
				dataSet = cheeseThis.parent().parent().buffer("CheeseListComponentDataSet"),
				dataSetCur = {},
				listType = [ "radio", "check", "onoff", "accordion", "img2", "img" ];

			for ( var i = 0, l = listType.length; i < l; i++)
			{
				if( cheeseThis.hasClass(listType[i]) )
				{
					dataSetCur.type = listType[i];
					break;
				}
			}

			if( i == l)
				dataSetCur.type = "text";

			dataSet.push( dataSetCur );
		});
	}

	//h Image 크기에 따라 Subtxt 가변적
	listRow.filter('.multiLine.img').each(function(){
		var cheeseThis = Cheese(this);
		if(cheeseThis.children('.img').children('img').size()!=0){
		cheeseThis.children('.subTxt').css("width", (430- cheeseThis.children('.img').children('img').width()) + "px");
		} else{
		cheeseThis.children('.subTxt').css("width", (430- cheeseThis.children('.img').width()) + "px");
		}
	})

	//h Image 크기에 따라 1 line일때 Line-height 변경 (중앙정렬위해)
	listRow.filter('.img').each(function(){
		var cheeseThis = Cheese(this);
		cheeseThis.css("line-height", (cheeseThis.children('.img').children('img').height() + 28) +"px")
	})

	// Checkbox Component Default Setting
	listRow.not('.check').not('.accordion').not('.radio').not('.onoff').tap( function() {

		var	cheeseThis = Cheese(this),
			listDataSet = cheeseThis.parent().parent().buffer("CheeseListComponentDataSet"),
			idx = cheeseThis.index();

		if ( typeof listDataSet[idx].func == "function" )
			listDataSet[idx].func.apply(this, listDataSet[idx].funcArgs);
	});

	// Checkbox Component Default Setting
	listRow.filter('.check').prepend('<div class="innerCom"><div class="symCheck"><div class="comCheckboxObj1"></div><div class="comCheckboxObj2"></div></div></div>')
			.tap( function() {

		var	cheeseThis = Cheese(this),
			listDataSet = cheeseThis.parent().parent().buffer("CheeseListComponentDataSet"),
			idx = cheeseThis.index(),
			liSym = cheeseThis.children('.innerCom').children('.symCheck');

		liSym.toggleClass('on');
		listDataSet[ idx ].select = liSym.hasClass('on');

		if ( typeof listDataSet[idx].func == "function" )
			listDataSet[idx].func.apply(this, listDataSet[idx].funcArgs);
	});

	// onoff Component Default Setting
	listRow.filter('.onoff').prepend('<div class="innerCom"><div class="symOnoff"><div class="symOnoffOnBg"></div></div>')
			.tap( function() {

		var cheeseThis = Cheese(this),
			listDataSet = cheeseThis.parent().parent().buffer("CheeseListComponentDataSet"),
			idx = cheeseThis.index(),
			liSym = cheeseThis.children('.innerCom').children('.symOnoff');

		liSym.toggleClass('on');
		listDataSet[ idx ].select = liSym.hasClass('on');

		if ( typeof listDataSet[idx].func == "function" )
			listDataSet[idx].func.apply(this, listDataSet[idx].funcArgs);
	});

	// radio Component Default Setting
	listRow.filter('.radio').prepend('<div class="innerCom"><div class="symRadio"><div class="comRadioObj"></div><div class="comRadioOnShadow"></div></div>')
			.tap( function() {

		var cheeseThis = Cheese(this),
			listDataSet = cheeseThis.parent().parent().buffer("CheeseListComponentDataSet"),
			idx = cheeseThis.index(),
			liSym = cheeseThis.children('.innerCom').children('.symRadio'),
			liThisRow = cheeseThis.parent().children('li');

		for( var k in listDataSet )
			if( listDataSet[k].type == "radio" )
			{
				listDataSet[k].select = false;
				liThisRow.eq(k).children('.innerCom').children('.symRadio').removeClass('on');
			}

		listDataSet[ idx ].select = true;
		liSym.addClass('on');

		if ( typeof listDataSet[idx].func == "function" )
			listDataSet[idx].func.apply(this, listDataSet[idx].funcArgs);
	});

	//h Radio, Checkbox, Onoff, Delete 가 있을때 List 값 조정
	listRow.children(".innerCom").each( function(){
		var cheeseThis = Cheese(this),
			cheeseThisParent = cheeseThis.parent();

		// Adjust Sub Text width
		cheeseThis.siblings('.subTxt').css('width','390px');

		//h 한줄일 때 컴포넌트 위치 조정
		if(! cheeseThisParent.hasClass('multiLine'))
		{
			var pH = window.parseInt(cheeseThisParent.css("line-height"));
			cheeseThis.css("margin-top",(pH-(pH/2+20))+"px");
		}

		//h 오른쪽, 왼쪽 방향에 따른 Margin
		if(cheeseThis.css('float') == "left")
			cheeseThis.css('margin-right','10px');
	});

	// Accordion Component Default Setting
	listRow.filter('.accordion').append("<div class='ico_accordion'></div>") //Icon
			.each(function() {

		var cheeseThis = Cheese(this);
		cheeseThis.contents().not( cheeseThis.children('.accCon').dom() ).wrapAll('<span></span>'); //Wrap touch Area
	})
			.children('.accCon').prepend("<div class='subBack'></div>"); //Sub Background

	// Accordion Interaction
	listRow.children('span').tap( function()
	{
		var accChild = Cheese(this).next('.accCon'),
			accIco = Cheese(this).children(".ico_accordion"),
			liThis = Cheese(this);

		if( !accIco.hasClass("on") )
		{
			if ( !liThis.buffer("CheeseAccordionComponentDataHeight") )
				liThis.buffer("CheeseAccordionComponentDataHeight", accChild.height() );

			accChild.removeClass('accClose');
			accChild.addClass("on");

			accChild.css("height", liThis.buffer("CheeseAccordionComponentDataHeight") +"px");
			accIco.addClass("on");
		}
		else
		{
			accChild.addClass('accClose');
			accIco.removeClass("on");
		}

		var listDataSet = Cheese(this).parent().parent().parent().buffer("CheeseListComponentDataSet"),
			idx = Cheese(this).parent().index();

		if ( typeof listDataSet[idx].func == "function" )
			listDataSet[idx].func.apply(this, listDataSet[idx].funcArgs);
	});
}

//h select() -> 선택된 것들의 배열
//h select(key) -> 이놈을 선택 ( 아직 미구현 )
CheeseList.prototype.select = function ()
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseListComponentDataSet"),
		rArray = new Array();

	for ( var k in dataSet)
		if( dataSet[k].select == true)
			rArray.push( dataSet[k].key );

	return rArray;
};


CheeseList.prototype.rss = function ( _url, _tagOpts, _opts, _toXmlSuccessCallBackSet )
{
	if( arguments.length == 1 && typeof arguments[0] == "object" )
	{
		var args = arguments[0];
		_url = args[0];
		_tagOpts = args[1];
		_opts = args[2];
		//h 사용자가 RSS 에서 xml Callback() 을 입력.
		_toXmlSuccessCallBackSet = args[3];
	}

	var cheeseThis = Cheese(this);

	var tagInfo = {};
	tagInfo.title = "title";
	tagInfo.description = "description";
	tagInfo.link = "link";
	tagInfo.image = "image";

	for( var k in _tagOpts )
	{
		if( k == "title" )
			tagInfo.title = _tagOpts[k];
		else if(k=="description")
			tagInfo.description = _tagOpts[k];
		else if(k == "link")
			tagInfo.link = _tagOpts[k];
		else if(k == "image")
			tagInfo.image = _tagOpts[k];
	}

	var opts = {};
	opts.iterator = "item";
	opts.imageType = "img";
	for ( var k in _opts )
		opts[k] = _opts[k];

	var ajaxOpts = {},
		ajaxOptsTemp = (_opts)?_opts.ajaxOption:null;
	for ( var k in ajaxOptsTemp )
		ajaxOpts[k] = _opts.ajaxOption[k];

	var eFunc = ajaxOpts.e,
		aFunc = ajaxOpts.a,
		tFunc = ajaxOpts.t,
		rFunc = ajaxOpts.r;

	if ( typeof eFunc == "function" )
		ajaxOpts.e = function () {
			Cheese.pop.back();
			if( typeof eFunc == "function" )
				eFunc();
		};

	if ( typeof aFunc == "function" )
		ajaxOpts.a = function () {
			Cheese.pop.back();
			if( typeof aFunc == "function" )
				aFunc();
		};

	if ( typeof rFunc == "function" )
		ajaxOpts.r = function () {
			Cheese.pop.back();
			if( typeof rFunc == "function" )
				rFunc();
		};

	if ( typeof tFunc == "function" )
		ajaxOpts.t = function () {
			Cheese.pop.back();
			if( typeof tFunc == "function" )
				tFunc();
		};

	if ( opts.titleLen )
		cheeseThis.buffer("CheeseListComponentDataTitleLen", opts.titleLen);
	if ( opts.descriptionLen )
		cheeseThis.buffer("CheeseListComponentDataSubLen", opts.descriptionLen);

	cheeseThis.buffer("CheeseListComponentDataRSSURL", _url)
			.buffer("CheeseListComponentDataRSSTagOpts", _tagOpts)
			.buffer("CheeseListComponentDataRSSROpts", _opts)
			.buffer("CheeseListComponentDataRSSFlag", true)
			.buffer("CheeseListComponentDataRSSTime", Cheese.now() );

	Cheese.pop('#busyIndicator');
	Cheese.xml( _url, function ( _xml )
		{
			var dataSet = new Array();
			var itemElem = _xml.selector(opts.iterator);

			var strStorage = "<CheeseRSSData>";
			for ( var i=0, l=itemElem.size(); i<l; i++ )
			{
				strStorage += "<item>";

				var dataSetCur = new Array();
				dataSetCur.push( "text" );

				if( tagInfo.image )
				{
					var elem = itemElem.eq(i).find(tagInfo.image);

					if( elem.size() != 0 )
					{
						var strSelect = Cheese.trim(tagInfo.image);
						if( strSelect.substr(strSelect.length-1, strSelect.length) == ']' )
						{

							var attr = Cheese.trim( strSelect.substring( strSelect.lastIndexOf("[")+1 , strSelect.lastIndexOf("]") ) ),
								imgSrc = elem.attr(attr);

							if( imgSrc )
							{
								dataSetCur[0] = opts.imageType ;
								dataSetCur.push( imgSrc );
							}
						}
						else if ( Cheese.trim(elem.text()) )
						{
							dataSetCur[0]  = opts.imageType;
							dataSetCur.push( Cheese.trim( elem.text()) );
						}
					}

					dataSetCur.push( itemElem.eq(i).find(tagInfo.title).text() );
					if( opts.description != "none" ) dataSetCur.push( itemElem.eq(i).find(tagInfo.description).text() );
					if( typeof opts.func == "function" )
					{
						dataSetCur.push( opts.func );
					}
					else if( opts.link != "none" && Cheese.trim(itemElem.eq(i).find(tagInfo.link).text()) )
					{
						var linkURL = itemElem.eq(i).find(tagInfo.link).text();

						strStorage += "<link>"+ linkURL + "</link>";
						dataSetCur.push( [
							function ( _url ) { Cheese.openURL( _url ); },
							linkURL
						] );
					}

					dataSet.push(dataSetCur);

					strStorage += "<type>" + dataSetCur[0] + "</type>";
					if( dataSet[i][0] == opts.imageType )
					{
						strStorage += "<image>" + dataSetCur[1] + "</image>";
						strStorage += "<title>" + dataSetCur[2] + "</title>";
						strStorage += "<description>" + dataSetCur[3] + "</description>";
					}
					else
					{
						strStorage += "<title>" + dataSetCur[1] + "</title>";
						strStorage += "<description>" + dataSet[i][2] + "</description>";
					}

					strStorage += "</item>";
				}
			}
			strStorage += "</CheeseRSSData>";
			Cheese.storage("CheeseRSSData" +CheeseGlobal.name + cheeseThis.dom().id, strStorage );

			cheeseThis.data(dataSet);
			Cheese.pop.back();

			//h 사용자가 RSS 에서 xml Callback() 을 입력했을 경우 실행.
			if ( _toXmlSuccessCallBackSet && typeof( _toXmlSuccessCallBackSet ) == 'object' && typeof( _toXmlSuccessCallBackSet.func ) == 'function' )
			{
				var tArgs = new Array();
				tArgs.push( cheeseThis );
				for ( var lp = 0; lp < _toXmlSuccessCallBackSet.args.length; lp++ )
				{
					tArgs.push( _toXmlSuccessCallBackSet.args[ lp ] );
				};

				_toXmlSuccessCallBackSet.func.apply( cheeseThis, tArgs );
			};

		}, ajaxOpts  );
}

CheeseList.prototype.rssCache = function ()
{
	var strXML = Cheese.storage( "CheeseRSSData" +CheeseGlobal.name + this.id );

	if ( !strXML )
		return;

	var itemElem = Cheese.xmlSelector ( ( new DOMParser() ).parseFromString( strXML, "application/xml" ) , "item" ),
		dataSet = new Array();

	for ( var i=0, l=itemElem.size(); i<l; i++ )
	{
		var dataSetCur = new Array();
		var type = itemElem.eq(i).find("type").text();
		dataSetCur.push( type );

		if( type == "img" || type == "img2" )
			dataSetCur.push( itemElem.eq(i).find("image").text() );

		dataSetCur.push( itemElem.eq(i).find("title").text() );
		dataSetCur.push( itemElem.eq(i).find("description").text() );
		dataSetCur.push( [
			function ( _url ) { Cheese.openURL( _url ); },
			itemElem.eq(i).find("link").text()
		] );

		dataSet.push(dataSetCur);
	}

	Cheese(this).data( dataSet );
}

CheeseList.prototype.func = function ( _data )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseListComponentDataSet");
	if( !dataSet )
		cheeseThis.buffer("CheeseListComponentDataSet", dataSet = new Array() );

	if( typeof _data == "object" )
		for ( var k in _data)
			dataSet[k].func = _data[k];
}

CheeseList.prototype.sub = function ( _key )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseListComponentDataSet");
	if( !dataSet )
		cheeseThis.buffer("CheeseListComponentDataSet", dataSet = new Array() );

	if( typeof _key == "string" )
	{
		for ( var k in dataSet)
			if( dataSet[k].key == _key )
				return cheeseThis.sub( window.parseInt(k) );
	}
	else if ( typeof _key == "number")
		return cheeseThis.children('ul').children('li').eq(_key);
	else
		cheeseThis.children('ul').children('li').eq();

}

CheeseList.prototype.removeItem = function ( _key )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseListComponentDataSet");
	if( !dataSet )
		cheeseThis.buffer("CheeseListComponentDataSet", dataSet = new Array() );

	if( typeof _key == "string" )
	{
		for ( var k in dataSet)
			if( dataSet[k].key == _key )
				cheeseThis.remove( window.parseInt(k) );
	}
	else if ( typeof _key == "number")
	{
		var dataSetTemp = new Array();

		for( var i = 1, l = dataSet.length - _key; i< l; i++)
			dataSetTemp.push( dataSet.pop() );

		dataSet.pop();

		for( var i = 0, l = dataSetTemp.length; i< l; i++)
			dataSet.push( dataSetTemp.pop() );

		cheeseThis.sub(_key).remove();
	}
}





// Cheese SetList Component
var CheeseSetList = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "setList";
}

CheeseSetList.prototype.data = function ( _data )
{
	var cheeseThis = Cheese(this);
	if( !_data )
		return cheeseThis.buffer("CheeseSetListComponentDataSet");

	var inHTML = "<ul>",
		dataSet = new Array(),
		data;

	if( typeof _data[1] == "function" )
	{
		data = _data[0];
		cheeseThis.buffer( "CheeseSetListComponentDataFunc", _data[1] );
	}
	else
		data = _data;


	// save data
	for( var k in data )
	{
		var dataSetCur = {},
			i = 0;

		dataSetCur.key = k;
		dataSetCur.type = data[k][i++];

		if( dataSetCur.type == "img" || dataSetCur.type == "img2" )
			dataSetCur.img = data[k][i++];
		else if( typeof data[k][i] == "boolean" )
			dataSetCur.select =data[k][i++];

		dataSetCur.title = data[k][i++];

		if( typeof data[k][i] == "string" )
			dataSetCur.subTitle = data[k][i++];

		dataSet.push(dataSetCur);

												inHTML += '<li' + ((dataSetCur.type=="radio" || dataSetCur.type=="check" || dataSetCur.type=="onoff")?' class="'+ dataSetCur.type+'"':'') + '>';
		if( dataSetCur.img )
			if(dataSetCur.type=="img") 			inHTML += '<div class="img"><img src="' + dataSetCur.img + '"></div>' + '<div class="txt">' + dataSetCur.title + '</div>';
			else 								inHTML += '<div class="txt">' + dataSetCur.title + '</div>' + '<div class="img"><img src="' + dataSetCur.img + '"></div>';
		else 									inHTML += '<div class="txt">' + dataSetCur.title + '</div>';

		if( dataSetCur.subTitle ) 				inHTML += '<div class="subTxt">' + dataSetCur.subTitle + '</div>';
												inHTML += '</li>';

	}
	inHTML += "</ul>";

	cheeseThis.buffer("CheeseSetListComponentDataSet", dataSet );
	cheeseThis.html(inHTML);
	cheeseThis.set();

	for( var k in dataSet )
		if( dataSet[k].select )
			cheeseThis.select( dataSet[k].key );
}

CheeseSetList.prototype.count = function ()
{
	return Cheese(this).children('ul').children('li').size();
}

CheeseSetList.prototype.set = function ( )
{
	// List Component Default Setting
	var cheeseThis = Cheese(this),
		listRow = cheeseThis.children('ul').children('li');

	// Add to list css property
	cheeseThis.addClass("list");
	if( !cheeseThis.buffer("CheeseSetListComponentDataSet") )
	{
		cheeseThis.buffer("CheeseSetListComponentDataSet", new Array() );
		listRow.each ( function (idx) {
			var cheeseThis = Cheese(this),
				dataSet = cheeseThis.parent().parent().buffer("CheeseSetListComponentDataSet"),
				dataSetCur = {},
				listType = [ "radio", "check", "onoff", "img2", "img" ];

			for ( var i = 0, l = listType.length; i < l; i++)
			{
				if( cheeseThis.hasClass(listType[i]) )
				{
					dataSetCur.type = listType[i];
					break;
				}
			}
			if( i == l)
				dataSetCur.type = "text";
			dataSetCur.key = idx;

			dataSet.push( dataSetCur );
		});
	}

	listRow.prepend("<div class='listLineTop'></div>"+		// Blank DIV Element for LineTop
					"<div class='listLineBottom'></div>"+		// Blank DIV Element for LineBottom
					"<div class='glow'></div>"); 		// Blank DIV Element for Gradient

	listRow.touchStart(	function() { Cheese(this).addClass('focus'); })
			.touchEnd(		function() { Cheese(this).removeClass('focus'); });

	listRow.each( function() {

		var cheeseThis = Cheese(this);
		cheeseThis.children('.subTxt').parent().addClass("multiLine"); //add multiline class

		//h add img class - 타입에 따라 두가지로 된다.
		if( cheeseThis.children('.img').size() != "0")
		{
			cheeseThis.addClass("img");
			if( !cheeseThis.children('.img').next().hasClass('txt') )
				cheeseThis.addClass("img2")
		};
	})

	//h Image 크기에 따라 Subtxt 가변적
	listRow.filter('.multiLine.img').each(function(){
		var cheeseThis = Cheese(this);
		cheeseThis.children('.subTxt').css("width", (430- cheeseThis.children('.img').children('img').width()) + "px");
	})

	//h Image 크기에 따라 1 line일때 Line-height 변경 (중앙정렬위해)
	listRow.filter('.img').each(function(){
		var cheeseThis = Cheese(this);
		cheeseThis.css("line-height", (cheeseThis.children('.img').children('img').height() + 28) +"px")
	})

	// Checkbox Component Default Setting
	listRow.filter('.check').prepend('<div class="innerCom"><div class="symCheck"><div class="comCheckboxObj1"></div><div class="comCheckboxObj2"></div></div></div>')
			.tap( function() {

		var	cheeseThis = Cheese(this),
			listDataSet = cheeseThis.parent().parent().buffer("CheeseSetListComponentDataSet"),
			idx = cheeseThis.index(),
			liSym = cheeseThis.children('.innerCom').children('.symCheck');

		liSym.toggleClass('on');
		listDataSet[ idx ].select = liSym.hasClass('on');
	});

	// onoff Component Default Setting
	listRow.filter('.onoff').prepend('<div class="innerCom"><div class="symOnoff"><div class="symOnoffOnBg"></div></div>')
			.tap( function() {

		var cheeseThis = Cheese(this),
			listDataSet = cheeseThis.parent().parent().buffer("CheeseSetListComponentDataSet"),
			idx = cheeseThis.index(),
			liSym = cheeseThis.children('.innerCom').children('.symOnoff');

		liSym.toggleClass('on');
		listDataSet[ idx ].select = liSym.hasClass('on');
	});

	// radio Component Default Setting
	listRow.filter('.radio').prepend('<div class="innerCom"><div class="symRadio"><div class="comRadioObj"></div><div class="comRadioOnShadow"></div></div>')
			.tap( function() {

		var cheeseThis = Cheese(this),
			listDataSet = cheeseThis.parent().parent().buffer("CheeseSetListComponentDataSet"),
			idx = cheeseThis.index(),
			liSym = cheeseThis.children('.innerCom').children('.symRadio'),
			liThisRow = cheeseThis.parent().children('li');

		for( var k in listDataSet )
			if( listDataSet[k].type == "radio" )
			{
				listDataSet[k].select = false;
				liThisRow.eq(k).children('.innerCom').children('.symRadio').removeClass('on');
			}

		listDataSet[ idx ].select = true;
		liSym.addClass('on');
	});

	//h Radio, Checkbox, Onoff, Delete 가 있을때 List 값 조정
	listRow.children(".innerCom").each( function(){
		var cheeseThis = Cheese(this),
			cheeseThisParent = cheeseThis.parent();

		//h Sub Text width 값 조정
		cheeseThis.siblings('.subTxt').css('width','390px');

		//h 한줄일때 Component 위치 조정
		if(! cheeseThisParent.hasClass('multiLine'))
		{
			var pH = window.parseInt(cheeseThisParent.css("line-height"));
			cheeseThis.css("margin-top",(pH-(pH/2+20))+"px");
		}

		//h 오른쪽, 왼쪽 방향에 따른 Margin
		if(cheeseThis.css('float') == "left")
			cheeseThis.css('margin-right','10px');
	});
}

CheeseSetList.prototype.execFunc = function ()
{
	var cheeseThis = Cheese(this),
		func = cheeseThis.buffer("CheeseSetListComponentDataFunc");
	if( typeof func == "function" )
		func.call(this, cheeseThis.select() );
}

CheeseSetList.prototype.select = function ( _key, _value )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseSetListComponentDataSet");

	if( !dataSet )
		return null;
	else if( typeof _key == "string" )
	{
		for( var i = 0; dataSet[i]; i++)
			if( dataSet[i].key == _key )
				cheeseThis.select(i, _value);
	}
	else if ( typeof _key == "number" && dataSet[_key])
	{
		var liAll = cheeseThis.children('ul').children('li'),
			liSelect = liAll.eq(_key),
			liSym;

		if( dataSet[_key].type == "check" )
			liSym = liSelect.children('.innerCom').children('.symCheck');
		else if ( dataSet[_key].type == "onoff" )
			liSym = liSelect.children('.innerCom').children('.symOnoff');
		else if ( dataSet[_key].type == "radio" )
		{
			for( var i = 0; dataSet[i]; i++)
				if( dataSet[i].type == "radio")
					dataSet[i].select = false;

			liAll.children('.innerCom').children('.symRadio').removeClass('on');
			liSym = liSelect.children('.innerCom').children('.symRadio');
		}

		if ( liSym )
		{
			if(_value == "off")
			{
				liSym.removeClass('on');
				dataSet[ _key ].select = false;
			}
			else
			{
				liSym.addClass('on');
				dataSet[ _key ].select = true;
			}
		}

	}
	else
	{
		var rArray = new Array();

		for ( var k in dataSet)
			if( dataSet[k].select == true)
				rArray.push( dataSet[k].key );

		return rArray;
	}
}

CheeseSetList.prototype.func = function ( _func )
{
	Cheese(this).buffer("CheeseSetListComponentDataFunc", _func );
}









// Cheese Tab Component
var CheeseTab = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "tab";
}

CheeseTab.prototype.option = function ( _data )
{
	for ( var k in _data)
	{

		if(k == "background"){
			if (_data[k][0] == "color"){
				Cheese(this).find('li').not('.on').css("background",_data[k][1]);
			}

			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).find('li').not('.on').css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				} else {
					Cheese(this).find('li').not('.on').addClass("c_"+_data[k][1]);
				}
			}
		}

		if(k == "focusBackground")
		{
			if (_data[k][0] == "color"){
				Cheese(this).find('li.on').css("background",_data[k][1]);
			}

			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1)
				{
					Cheese(this).find('li.on').css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				}
				else
				{
					Cheese(this).find('li.on').addClass("c_"+_data[k][1]);
				}
			}
		}

		if(k == "fontColor")
		{
			Cheese(this).find('li').not('.on').css("color",_data[k]);
		}

		if(k == "fontSize"){
			if (_data[k] == "big"){
				Cheese(this).find('li').css("font-size","32px");
			} else if (_data[k] == "normal"){
				Cheese(this).find('li').css("font-size","28px");
			} else if (_data[k] == "small"){
				Cheese(this).find('li').css("font-size","24px");
			} else {
				Cheese(this).find('li').css("font-size",_data[k]);
			}
		}

		if(k == "focusFontColor")
		{
			Cheese(this).find('li.on').css("color",_data[k]);
		}


		if(k == "glow")
		{
			if (_data[k] == "true"){
				Cheese(this).find('.glow').show();
			} else if (_data[k] == "false"){
				Cheese(this).find('.glow').hide();
			}
		}

		if(k == "lineOpacity")
		{
			Cheese(this).find(".tabBorder").css("opacity",_data[k]);

		}

		if(k == "lineColorLight")
		{
			Cheese(this).find('.tabBorder').css("border-left-color",_data[k]);
		}


		if(k == "lineColorDark")
		{
			Cheese(this).find('.tabBorder').css("border-right-color",_data[k]);
		}

		if( k =="maxLen" )
		{
			Cheese(this).parent().find('.list').option( { "maxLen" : _data[k] } );
		}

		if( k == "transOption" )
		{
			Cheese(this).buffer("CheeseTabComponentDataTransOption", _data[k] );
		}
	}

}

CheeseTab.prototype.count = function ()
{
	return Cheese(this).children('ul').children('li').size();
}

CheeseTab.prototype.set = function ( )
{
	var cheeseThis = Cheese(this),
		cheeseThisUl= cheeseThis.children('ul'),
		lis = cheeseThisUl.children('li');


	lis.prepend("<div class='innerGrd'></div>"+		// Blank DIV Element for Border
				"<div class='tabBorder'></div>"); 	// Blank DIV Element for Border

	cheeseThis.prepend("<div class='glow'></div>");	// Blank DIV Element for Glow

	if ( !cheeseThis.buffer("CheeseTabComponentDataSet") )
	{
		cheeseThis.buffer("CheeseTabComponentDataSet", new Array() );
		cheeseThis.children('ul').children('li').each ( function () {
			var cheeseThis = Cheese(this),
				dataSet = cheeseThis.parent().parent().buffer("CheeseTabComponentDataSet"),
				dataSetCur = {};

			dataSetCur.key = Cheese.trim( cheeseThis.text() );
			dataSetCur.enable = true;
			dataSet.push( dataSetCur );
		});
	}

	Cheese('.asdasd').tap(function(){
		lis.each(function(){
			alert(cheeseThis.attr("class"));
		})
	})

	lis.tap( function() {

		var liThis = Cheese(this),
			tabCheese = Cheese(this).parent().parent();
		tabCheese.go( liThis.index() );
	});

	cheeseThis.go(0); //First Scene View
}

CheeseTab.prototype.data = function ( _data )
{
	var cheeseThis = Cheese(this);
	if( !_data )
		return cheeseThis.buffer("CheeseTabComponentDataSet");

	var dataSet = new Array(),
		inHTML = "<ul>",
		sceneHTML = "";

	for( var k in _data )
	{
		var dataSetCur = {};
		dataSetCur.key = k;
		dataSetCur.enable = true;
		if( typeof _data[k] == "string" )
			dataSetCur.sub = _data[k];
		else if( typeof _data[k] == "object" )
		{
			dataSetCur.sub = _data[k][0];
			dataSetCur.viewFunc = _data[k][1];
			dataSetCur.func = _data[k][2];
		}

		dataSet.push( dataSetCur );

		inHTML += "<li>" + dataSetCur.key + "</li>";
		sceneHTML += "<div class='subScene'>" + dataSetCur.sub + "</div>";
	}

	inHTML += "</ul>";

	cheeseThis.html(inHTML);
	cheeseThis.after(sceneHTML);
	cheeseThis.buffer("CheeseTabComponentDataSet", dataSet);
	cheeseThis.buffer("CheeseTabComponentDataCurTab", null);
	cheeseThis.set();
}


CheeseTab.prototype.go = function ( _tab, _opts )
{
	if (typeof _tab == "number")
	{
			var cheeseThis = Cheese(this),
			dataSet = cheeseThis.buffer("CheeseTabComponentDataSet"),
			curTab = cheeseThis.buffer("CheeseTabComponentDataCurTab"),
			subScene = cheeseThis.siblings('.subScene'),
			tabList = cheeseThis.children('ul').children('li');

		if(  curTab === _tab )
			return;

		if( !dataSet )
			cheeseThis.buffer("CheeseTabComponentDataSet", dataSet = new Array() );

		tabList.removeClass('on');
		tabList.eq(_tab).addClass('on');

		cheeseThis.buffer("CheeseTabComponentDataCurTab", _tab);

		var second = 0;
		if( typeof curTab != "number" || CheeseGlobal.tabPageTimming == "after")
		{
			second = 0;
		}
		else if ( _opts )
		{
			if( _opts.transEffect == "none" ) second = 0;
			else second = window.parseFloat( _opts.transSecond );
		}
		else if ( cheeseThis.buffer("CheeseTabComponentDataTransOption") )
		{
			if ( cheeseThis.buffer("CheeseTabComponentDataTransOption").transeffect == "none" ) second = 0;
			else second = window.parseFloat( cheeseThis.buffer("CheeseTabComponentDataTransOption").transSecond );
		}
		else
		{
			if ( CheeseGlobal.transeffect == "none" ) second = 0;
			else second = window.parseFloat( CheeseGlobal.transSecond );
		}

		window.setTimeout( function() {
			if ( dataSet[_tab] )
			{
				if ( !dataSet[_tab].viewCheck && dataSet[_tab].viewFunc )
				{
					dataSet[_tab].viewFunc.call( cheeseThis.dom(), _tab );
					dataSet[_tab].viewCheck = true;
				}

				if ( dataSet[_tab].func )
					dataSet[_tab].func.call( cheeseThis.dom(), _tab );
			}
		}, second*1000 );


		if( typeof curTab != "number")
		{
			subScene.hide();
			subScene.eq(_tab).show();
		}
		else
		{
			Cheese.transition(
				subScene.eq(_tab),
				subScene.eq(curTab), (_opts)?_opts:cheeseThis.buffer("CheeseTabComponentDataTransOption") );
		}
	}
}

CheeseTab.prototype.func = function ( _data )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseTabComponentDataSet");
	if( !dataSet )
		return true;

	if( typeof _data == "object" )
		for ( var k in _data)
			dataSet[k].func = _data[k];
}

CheeseTab.prototype.viewFunc = function ( _data )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseTabComponentDataSet");
	if( !dataSet )
		cheeseThis.buffer("CheeseTabComponentDataSet", dataSet = new Array() );

	if( typeof _data == "object" )
		for ( var k in _data)
		{
			dataSet[k].viewFunc = _data[k];
			dataSet[k].viewCheck = false;
		}
}

CheeseTab.prototype.sub = function ( _idx )
{
	var cheeseThis= Cheese(this),
		idx = ( typeof _idx == "undefined" )? cheeseThis.buffer("CheeseTabComponentDataCurPage") : _idx ;
	return Cheese(this).siblings(".subScene").eq( idx );
}

CheeseTab.prototype.rss = function ( _data, _tagOpts, _opts, _toXmlSuccessCallBackSet )
{
	if( arguments.length == 1 && typeof arguments[0] == "object" )
	{
		var args = arguments[0];
		_data = args[0];
		_tagOpts = args[1];
		_opts = args[2];
		_toXmlSuccessCallBackSet = args[3];
	}

	if ( typeof _data == "object" )
	{
		var dataSet = new Array(),
			dataSetRSS = new Array();

		for( var k in _data )
		{
			dataSet[k] = [ "<div class='list' id='CheeseTabRSSList"+k+"'></div>",
								function ( idx ){
									var cheeseThis = Cheese(this),
										cheeseThisDataSetRSS = cheeseThis.buffer("CheeseTabComponentDataSetRSS");

									cheeseThis.sub(idx).find(".list").rss(
										cheeseThisDataSetRSS[ idx ].url,
										( cheeseThisDataSetRSS[idx].tagOpts ) ?
											cheeseThisDataSetRSS[idx].tagOpts :
											cheeseThis.buffer("CheeseTabComponentDataRSSTagOpts"),
										( cheeseThisDataSetRSS[idx].opts ) ?
											cheeseThisDataSetRSS[idx].opts :
											cheeseThis.buffer("CheeseTabComponentDataRSSOpts"),
										( cheeseThisDataSetRSS[idx].xmlSuccessCallBackSet ) ?
											cheeseThisDataSetRSS[idx].xmlSuccessCallBackSet :
											cheeseThis.buffer("CheeseTabComponentDataRSSXmlSuccessCallBackSet")
									);
								},
								function ( idx ) {
									Cheese.rssTime( Cheese(this).sub(idx).find('.list').buffer("CheeseListComponentDataRSSTime") );
								}
								];

			var dataSetRSSCur = {};
			dataSetRSSCur.url = (typeof _data[k] == "object")?_data[k][0]:_data[k];
			dataSetRSSCur.tagOpts = (typeof _data[k] == "object")?_data[k][1]:null;
			dataSetRSSCur.opts = (typeof _data[k] == "object")?_data[k][2]:null;
			dataSetRSSCur.xmlSuccessCallBackSet = (typeof _data[k] == "object")?_data[k][3]:null;
			dataSetRSS.push(dataSetRSSCur);
		}

		Cheese(this).buffer("CheeseTabComponentDataSet", dataSet)
					.buffer("CheeseTabComponentDataSetRSS", dataSetRSS)
					.buffer("CheeseTabComponentDataRSSTagOpts", _tagOpts)
					.buffer("CheeseTabComponentDataRSSOpts", _opts)
					.buffer("CheeseTabComponentDataRSSXmlSuccessCallBackSet", _toXmlSuccessCallBackSet )
					.data( dataSet );
	}
}

CheeseTab.prototype.refresh = function ()
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseTabComponentDataSet"),
		curTab = cheeseThis.buffer("CheeseTabComponentDataCurTab");

	if ( dataSet && dataSet[curTab] )
	{
		if ( dataSet[curTab].viewFunc )
		{
			dataSet[curTab].viewFunc.call( this, curTab );
			dataSet[curTab].viewCheck = true;
		}

		if ( dataSet[curTab].func )
			dataSet[curTab].func.call( this, curTab );
	}
}

CheeseTab.prototype.autoRefresh = function ( _time )
{
	var cheeseThis = Cheese(this),
		dataSet = cheeseThis.buffer("CheeseTabComponentDataSet"),
		curTab = cheeseThis.buffer("CheeseTabComponentDataCurTab");

	if( dataSet && typeof dataSet.timer == "number" )
	{
		Cheese.timer( dataSet.timer );
		dataSet.timer = null;
	}

	if( !_time )
		return;

	dataSet.timer = Cheese.timer( function() {
		if ( dataSet && dataSet[curTab] )
		{
			if ( dataSet[curTab].viewFunc )
			{
				dataSet[curTab].viewFunc.call( this, curTab );
				dataSet[curTab].viewCheck = true;
			}

			if ( dataSet[curTab].func )
				dataSet[curTab].func.call( this, curTab );
		}
	}, _time );
}




// Cheese Softkey Component
var CheeseSoftkey = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type="softkey";
}

CheeseSoftkey.prototype.data = function( _data, _type, _func )
{
	var cheeseThis = Cheese(this);
	cheeseThis.html("");

	if (!_data)
		return;

	if(!_type)
		_type = CheeseGlobal.softkeyType;

	if(!_func)
		_func = CheeseGlobal.softkeyFunc;

	cheeseThis.removeClass("type1 type2").addClass(_type);
	var dataSet = new Array();

	if( _type == "type1" )
	{
		var softKeyHTML = '<div class="shadow"></div><div class="normalList">'
						+'<div class="back"></div><ul class="keyList">';
		var moreHTML = "";

		var k = 0;
		for ( var curdata in _data )
		{
			// data
			var dataSetCur= new Array();
			dataSetCur.push( curdata ); // key value
			dataSetCur.push( _data[curdata] ); // function
			dataSet.push(dataSetCur);

			if( k<2 )
				softKeyHTML += ( "<li>" + curdata + "</li>" );
			else
				moreHTML += ( "<li>" + curdata + "</li>" );

			k++;
	    }

		softKeyHTML += ( dataSet.length > 3 )?'<li>More</li></ul></div><ul class="moreList">'+moreHTML : moreHTML;
	    softKeyHTML += "</ul>";

	    cheeseThis.html(softKeyHTML);
	    cheeseThis.buffer("CheeseSoftKeyData", dataSet);

		cheeseThis.children(".moreList").children("li").tap( function()
		{
			var softkeydata = cheeseThis.buffer("CheeseSoftKeyData");

			var func = softkeydata[Cheese(this).index()+2][1];
			func.call(this, Cheese(this).index()+2 );
			Cheese.softkey.moreOff();
		});

		//Softkey Width Set
		var keyObj =Cheese('.softkey.type1 ul.keyList li');
		var keyNum = keyObj.size();

		if(keyNum == 3 ){
			keyObj.css("width","131px");
		} else if (keyNum == 2 ){
			keyObj.css("width","198px");
		} else if (keyNum == 1 ){
			keyObj.css("width","398px");
		}

		var moreList=Cheese('.softkey.type1 ul.moreList');
		var moreObj = Cheese('.softkey.type1 ul.moreList li');
		var moreNum = moreObj.size();

		if (moreNum%2 == 0){
			moreObj.css("width","238px");
			Cheese('.softkey.type1 ul.moreList li:last-child').addClass('evenLast')
			Cheese('.softkey.type1 ul.moreList li:nth-last-child(2)').addClass('evenLast2')

		} else {
			moreObj.css("width","238px");
			Cheese('.softkey.type1 ul.moreList li:last-child').css("width","478px");
			Cheese('.softkey.type1 ul.moreList li:last-child').addClass('oddLast')
		}

		//Softkey more function
		Cheese( this ).find(".keyList > li").not( (dataSet.length>3)?2:null ).tap( function() {
			var softkeydata = Cheese(".softkey").buffer("CheeseSoftKeyData");

			var func = softkeydata[Cheese(this).index()][1];
			func.call( this, Cheese(this).index() );
			Cheese.softkey.moreOff();
		});

		if( dataSet.length  > 3 )
			Cheese( this ).find(".keyList > li").eq(2).tap(function(){
				if( moreList.css('bottom') == '70px')
				{
					var morekeyHeight = Math.abs(70-moreList.height());
					moreList.css('bottom','-'+morekeyHeight+'px');
				}
				else
				{
					moreList.css('bottom','70px');
				}
			});

		Cheese('.softkey .normalList .back').tap(function(){
			_func.call(this, -1);
		})

		Cheese('.softkey li').touchStart( function() { Cheese(this).addClass('focus'); })
					.touchEnd(function() { Cheese(this).removeClass('focus'); });
	}
	else
	{
		var softKeyHTML = '<div class="softkeyType2 up"><div class="btnOpen">'
						+ '<div class="shadow"></div><span class="softImg"></span></div><ul>';
		var i = 0;
		for ( var curdata in _data )
		{
			if(i==2)
			{
				var dataSetCur = new Array();
				dataSetCur.push( "Back" ); // key value
				dataSetCur.push( _func ); // function
				dataSet.push(dataSetCur);

				softKeyHTML += ( "<li>" + "Back" + "</li>" );
			}

			// data
			var dataSetCur = new Array();
			dataSetCur.push( curdata ); //key value
			dataSetCur.push( _data[curdata] ); //function
			dataSet.push(dataSetCur);

			softKeyHTML += ( "<li>" + curdata + "</li>" );
			i++;
	    }

	    if( i<=2)
	    {
    		var dataSetCur = new Array();
			dataSetCur.push( "Back" ); // key value
			dataSetCur.push( _func ); // function
			dataSet.push(dataSetCur);

			softKeyHTML += ( "<li>" + "Back" + "</li>" );
	    }
	    softKeyHTML += "</ul>";

	    Cheese(this).html(softKeyHTML);
	    Cheese(this).buffer("CheeseSoftKeyData", dataSet);

	    Cheese( this ).find("ul > li").tap(
		function()
		{
			var softkeydata = Cheese(".softkey").buffer("CheeseSoftKeyData");

			var func = softkeydata[Cheese(this).index()][1];
			func.call( this, (Cheese(this).index()>2)?Cheese(this).index()-1:Cheese(this).index() );
		});

		Cheese('.softkeyType2 .btnOpen').tap(function()
		{
			if( Cheese('.softkeyType2 .btnOpen').children('.softImg').hasClass("open") )
			{
				Cheese(this).parent().css('top',"0px");
				Cheese(this).children('.softImg').removeClass('open');
			}
			else
			{
				var softkeyHeight= Cheese(this).next().height()-70;
				Cheese(this).parent().css('top',-softkeyHeight+"px");
				Cheese(this).children('.softImg').addClass('open');
			}
		});


		var key2Obj = Cheese('.softkey.type2 .softkeyType2 li');
		var key2Num = key2Obj.size();
		var key2Last = key2Num%3;

		if(key2Last == 1){
		 Cheese('.softkey.type2 .softkeyType2 li:last-child').css('width','478px');
		} else if(key2Last == 2){
		 Cheese('.softkey.type2 .softkeyType2 li:last-child').css('width','238px');
		 var key2Last2 = key2Num-key2Last;
		 Cheese('.softkey.type2 .softkeyType2 li').eq(key2Last2).css('width','238px')
		}

		if(key2Num > 3)
			Cheese('.softkeyType2 .btnOpen').show();
		else
			Cheese('.softkeyType2 .btnOpen').hide();
	}
}








// Cheese Title Component
var CheeseTitle = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type="title";
}
CheeseTitle.prototype.option = function ( _data )
{
	for ( var k in _data)
	{
		if(k == "round"){
			if (_data[k] == "normal"){
				Cheese(this).addClass('round');
			} else if (_data[k] == "big"){
				Cheese(this).addClass("round big");
			} else if (_data[k] == "small"){
				Cheese(this).addClass("round small");
			} else if (_data[k] == "false"){
				Cheese(this).removeClass("round");
			} else {
				Cheese(this).css({
					"-webkit-border-top-left-radius" : _data[k],
					"-webkit-border-top-right-radius" : _data[k]
				});
				Cheese(this).children('.gradient').css({
					"-webkit-border-top-left-radius" : _data[k],
					"-webkit-border-top-right-radius" : _data[k]
				});
			}
		}

		if(k == "glow"){
			if (_data[k] == "true"){
				Cheese(this).children(".glow").show();
			} else if (_data[k] == "false"){
				Cheese(this).children(".glow").hide();
			}
		}

		if(k == "background"){
			if (_data[k][0] == "color"){
				Cheese(this).css("background",_data[k][1]);
			}


			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				} else {
					Cheese(this).addClass("c_"+_data[k][1]);

				}

			}

		}

		if(k == "pattern"){
			if (_data[k] == "true"){
				Cheese(this).children(".pattern").show();
			} else if (_data[k] == "false"){
				Cheese(this).children(".pattern").hide();
			}
		}

		if(k == "fontSize"){
			if (_data[k] == "big"){
				Cheese(this).css("font-size","38px");
			} else if (_data[k] == "normal"){
				Cheese(this).css("font-size","34px");
			} else if (_data[k] == "small"){
				Cheese(this).css("font-size","30px");
			} else {
				Cheese(this).css("font-size",_data[k]);
			}
		}

		if(k == "fontColor"){
			Cheese(this).css("color",_data[k]);
		}

		if(k == "textAlign"){
			Cheese(this).css("text-align",_data[k]);
		}
		if(k == "display")
		{
			if (_data[k] == "true"){
				Cheese(this).css("display","block");
			} else if (_data[k] == "false"){
				Cheese(this).css("display","none");
			}
		}
	}
}

CheeseTitle.prototype.set = function ()
{
	Cheese(this).append("<div class='pattern'></div>"		// Blank DIV Element for Pattern
					+"<div class='glow'></div>") 		// Blank DIV Element for Gradient
				.after('<div class="titleShadow"></div>'); // Shadow Element
}
CheeseTitle.prototype.data = function( _string )
{
    Cheese(this).text(_string).set();
}





//  Setting Title Component
var CheeseSetTitle = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type="setTitle";
}

CheeseSetTitle.prototype.option = function ( _data )
{
	for ( var k in _data)
	{
		if(k == "round"){
			if (_data[k] == "normal"){
				Cheese(this).addClass('round');
			} else if (_data[k] == "big"){
				Cheese(this).addClass("round big")
			} else if (_data[k] == "small"){
				Cheese(this).addClass("round small")
			} else if (_data[k] == "false"){
				Cheese(this).removeClass("round")
			} else {
				Cheese(this).css({
					"-webkit-border-top-left-radius" : _data[k],
					"-webkit-border-top-right-radius" : _data[k]
				});
				Cheese(this).children('.gradient').css({
					"-webkit-border-top-left-radius" : _data[k],
					"-webkit-border-top-right-radius" : _data[k]
				});
			}
		}

		if(k == "glow"){
			if (_data[k] == "true"){
				Cheese(this).children(".glow").show();
			} else if (_data[k] == "false"){
				Cheese(this).children(".glow").hide();
			}
		}

		if(k == "background"){
			if (_data[k][0] == "color"){
				Cheese(this).css("background-color",_data[k][1]);
			}


			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")");
				} else {
					Cheese(this).addClass("c_"+_data[k][1]);

				}

			}

		}

		if(k == "pattern"){
			if (_data[k] == "true"){
				Cheese(this).children(".pattern").show();
			} else if (_data[k] == "false"){
				Cheese(this).children(".pattern").hide();
			}
		}

		if(k == "fontSize"){
			if (_data[k] == "big"){
				Cheese(this).css("font-size","40px");
			} else if (_data[k] == "normal"){
				Cheese(this).css("font-size","36px");
			} else if (_data[k] == "small"){
				Cheese(this).css("font-size","32px");
			} else {
				Cheese(this).css("font-size",_data[k]);
			}
		}

		if(k == "fontColor"){
			Cheese(this).css("color",_data[k]);
		}

		if(k == "textAlign"){
			Cheese(this).css("text-align",_data[k]);
		}
		if(k == "display")
		{
			if (_data[k] == "true"){
				Cheese(this).css("display","block");
			} else if (_data[k] == "false"){
				Cheese(this).css("display","none");
			}
		}
	}
}


CheeseSetTitle.prototype.set = function ()
{
	Cheese(this).append("<div class='pattern'></div>"		// Blank DIV Element for Pattern
						+"<div class='glow'></div>") 		// Blank DIV Element for Gradient
				.after('<div class="titleShadow"></div>'); 	// Shadow Element
}
CheeseSetTitle.prototype.data = function( _string )
{
    Cheese(this).text(_string).set();

}


// Cheese Google Map
var CheeseGoogleMap = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "googleMap";
}

CheeseGoogleMap.prototype.set = function ()
{
    //d alert(Cheese('head').append(...));
}

CheeseGoogleMap.prototype.addMarker = function ( _data )
{
    var _map = Cheese(this).buffer("MAPID");
    if(!_map) return;

    var dataSetCur = _data != undefined ? _data: {};

    var lat = dataSetCur["lat"] != null ? dataSetCur["lat"] : 37.541;
    var lng = dataSetCur["lng"] != null ? dataSetCur["lng"] : 126.986;

    var maker = dataSetCur["image"] != null ? new google.maps.Marker({position: new google.maps.LatLng(lat,lng),map: _map,icon: dataSetCur["image"]}) : new google.maps.Marker({position: new google.maps.LatLng(lat,lng),map: _map});
    //h maker obj 생성

    if(!Cheese(this).buffer("mapMakerList"))
    {
        var array = new Array();
        dataSetCur["id"] != null ? array[dataSetCur["id"].toString()] = maker :array.push(maker);
        Cheese(this).buffer("mapMakerList",array);
    }
    else
    {
        var array = Cheese(this).buffer("mapMakerList");
        dataSetCur["id"] != null ? array[dataSetCur["id"].toString()] = maker :array.push(maker);
        Cheese(this).buffer("mapMakerList",array);
    }
}
CheeseGoogleMap.prototype.addOverlay = function ( _data )
{
    var _map = Cheese(this).buffer("MAPID");
    if(!_map) return;
    if(_data["image"] == null) return;

    var dataSetCur = _data != undefined ? _data: {};

    var startlat = dataSetCur["startLat"] != null ? dataSetCur["startLat"] : 30;
    var startlng = dataSetCur["startLng"] != null ? dataSetCur["startLng"] : 120;
    var endlat = dataSetCur["endLat"] != null ? dataSetCur["endLat"] : 36;
    var endlng = dataSetCur["endLng"] != null ? dataSetCur["endLng"] : 130;


    var imageRect = new google.maps.LatLngBounds(
        new google.maps.LatLng(startlat,startlng),
        new google.maps.LatLng(endlat,endlng)
    );


    var overlay =  new google.maps.GroundOverlay(_data["image"],imageRect);
    //h overlay obj 생성
    overlay.setMap(_map);
    if(!Cheese(this).buffer("mapOverlayList"))
    {
        var array = new Array();
        dataSetCur["id"] != null ? array[dataSetCur["id"].toString()] = overlay :array.push(overlay);
        Cheese(this).buffer("mapOverlayList",array);
    }
    else
    {
        var array = Cheese(this).buffer("mapOverlayList");
        dataSetCur["id"] != null ? array[dataSetCur["id"].toString()] = overlay :array.push(overlay);
        Cheese(this).buffer("mapOverlayList",array);
    }
}
CheeseGoogleMap.prototype.addCircle = function ( _data )
{
    var _map = Cheese(this).buffer("MAPID");
    if(!_map) return;

    var dataSetCur = _data != undefined ? _data: {};

    var lat = dataSetCur["lat"] != null ? dataSetCur["lat"] : 37.541;
    var lng = dataSetCur["lng"] != null ? dataSetCur["lng"] : 126.986;
    var radius = dataSetCur["radius"] != null ? dataSetCur["radius"] : 500;
    var strokeWeight = dataSetCur["strokeWeight"] != null ? dataSetCur["strokeWeight"] : 3;
    var strokeColor = dataSetCur["strokeColor"] != null ? dataSetCur["strokeColor"] : "0xF10000";
    var strokeOpacity = dataSetCur["strokeOpacity"] != null ? dataSetCur["strokeOpacity"] : 1;
    var fillColor = dataSetCur["fillColor"] != null ? dataSetCur["fillColor"] : "0xF10000";
    var fillOpacity = dataSetCur["fillOpacity"] != null ? dataSetCur["fillOpacity"] : 0;

    var circle = new google.maps.Circle({
				center : new google.maps.LatLng(lat,lng),
				radius : radius,
				strokeWeight : strokeWeight,
				strokeColor : strokeColor,
				strokeOpacity : strokeOpacity,
				fillColor : fillColor,
				fillOpacity : fillOpacity,
				map : _map
			});
    //h circle obj 생성

    if(!Cheese(this).buffer("mapCircleList"))
    {
        var array = new Array();
        dataSetCur["id"] != null ? array[dataSetCur["id"].toString()] = circle :array.push(circle);
        Cheese(this).buffer("mapCircleList",array);
    }
    else
    {
        var array = Cheese(this).buffer("mapCircleList");
        dataSetCur["id"] != null ? array[dataSetCur["id"].toString()] = circle :array.push(circle);
        Cheese(this).buffer("mapCircleList",array);
    }
}
CheeseGoogleMap.prototype.addLine = function ( _data )
{
    var _map = Cheese(this).buffer("MAPID");
    if(!_map) return;

    var dataSetCur = _data != undefined ? _data: {};

    if(_data["lat"] == null) return;
    if(_data["lng"] == null) return;
    if( _data["lat"].length != _data["lng"].length) return;

    var path = new Array();

    for(var i = 0;i<_data["lat"].length;i++)
    {
        path[i] = new google.maps.LatLng(_data["lat"][i],_data["lng"][i]);
    }
    var strokeColor = dataSetCur["strokeColor"] != null ? dataSetCur["strokeColor"] : "0xF10000";
    var strokeOpacity = dataSetCur["strokeOpacity"] != null ? dataSetCur["strokeOpacity"] : 1;
    var strokeWeight = dataSetCur["strokeWeight"] != null ? dataSetCur["strokeWeight"] : 5;

    var line = new google.maps.Polyline({
        path: path,
        strokeColor: strokeColor,
        strokeOpacity: strokeOpacity,
        strokeWeight: strokeWeight
    });
    //h Line obj 생성
    line.setMap(_map);
    if(!Cheese(this).buffer("mapLineList"))
    {
        var array = new Array();
        dataSetCur["id"] != null ? array[dataSetCur["id"].toString()] = line :array.push(line);
        Cheese(this).buffer("mapLineList",array);
    }
    else
    {
        var array = Cheese(this).buffer("mapLineList");
        dataSetCur["id"] != null ? array[dataSetCur["id"].toString()] = line :array.push(line);
        Cheese(this).buffer("mapLineList",array);
    }
}

CheeseGoogleMap.prototype.removeMarker = function ( _id )
{
    var array = Cheese(this).buffer("mapMakerList");
    if(!array) return;
    if(typeof _id == "number" && array.length < _id + 1) return;

    array[_id].setMap();
    delete array[_id];
    if(typeof _id == "number" )
    {
        var tempArray = new Array();
        for(var i = 0,j = 0;i<array.length;i++,j++)
        {
            if(i == _id) j++;
            tempArray[i] = array[j];
        }
        array = tempArray;
        delete tempArray;
    }
    Cheese(this).buffer("mapMakerList",array);
}

CheeseGoogleMap.prototype.removeOverlay = function ( _id )
{
    var array = Cheese(this).buffer("mapOverlayList");
    if(!array) return;
    if(typeof _id == "number" && array.length < _id + 1) return;

    array[_id].setMap();
    delete array[_id];
    if(typeof _id == "number" )
    {
        var tempArray = new Array();
        for(var i = 0,j = 0;i<array.length;i++,j++)
        {
            if(i == _id) j++;
            tempArray[i] = array[j];
        }
        array = tempArray;
        delete tempArray;
    }
    Cheese(this).buffer("mapOverlayList",array);
}

CheeseGoogleMap.prototype.removeCircle = function ( _id )
{
    var array = Cheese(this).buffer("mapCircleList");
    if(!array) return;
    if(typeof _id == "number" && array.length < _id + 1) return;

    array[_id].setMap();
    delete array[_id];
    if(typeof _id == "number" )
    {
        var tempArray = new Array();
        for(var i = 0,j = 0;i<array.length;i++,j++)
        {
            if(i == _id) j++;
            tempArray[i] = array[j];
        }
        array = tempArray;
        delete tempArray;
    }
    Cheese(this).buffer("mapCircleList",array);
}

CheeseGoogleMap.prototype.removeLine = function ( _id )
{
    var array = Cheese(this).buffer("mapLineList");
    if(!array) return;
    if(typeof _id == "number" && array.length < _id + 1) return;

    array[_id].setMap();
    delete array[_id];
    if(typeof _id == "number" )
    {
        var tempArray = new Array();
        for(var i = 0,j = 0;i<array.length;i++,j++)
        {
            if(i == _id) j++;
            tempArray[i] = array[j];
        }
        array = tempArray;
        delete tempArray;
    }
    Cheese(this).buffer("mapLineList",array);
}

CheeseGoogleMap.prototype.getMarker = function ( _id )
{
    var array = Cheese(this).buffer("mapMakerList");
    if(!array) return;

    return array[_id];
}

CheeseGoogleMap.prototype.getOverlay = function ( _id )
{
    var array = Cheese(this).buffer("mapOverlayList");
    if(!array) return;

    return array[_id];
}

CheeseGoogleMap.prototype.getCircle = function ( _id )
{
    var array = Cheese(this).buffer("mapCircleList");
    if(!array) return;

    return array[_id];
}

CheeseGoogleMap.prototype.getLine = function (_id)
{
    var array = Cheese(this).buffer("mapLineList");
    if(!array) return;

    return array[_id];
}

CheeseGoogleMap.prototype.getMap = function ( _num )
{
    return Cheese(this).buffer("MAPID");
}

CheeseGoogleMap.prototype.zoom = function ( _zoom )
{
    var _map = Cheese(this).buffer("MAPID");

    if(arguments.length == 0)
        return _map != null ? _map.getZoom() : null;
    _map.setZoom(_zoom);
}

//d 인자값이 없을경우에 zoom value 가져온다.
//d 양수일경우 양수만큼 줌 올린다.
//d 음수의 경우는 음수의 크기만큼 줌을 내린다.
CheeseGoogleMap.prototype.center = function ( _lat , _lng )
{
    var _map = Cheese(this).buffer("MAPID");
    if(arguments.length == 0)
        return _map != null ? new Array(_map.getCenter().lat(),_map.getCenter().lng()) : null;

    _map.setCenter(new google.maps.LatLng(_lat, _lng));
}

CheeseGoogleMap.prototype.addEvent = function ( _obj , _eventType , _func)
{
    //d var R = google.maps.event.addListener(__map, "click", function(pt)
    var _map = Cheese(this).buffer("MAPID");
    if(!_map) return;

    var event = google.maps.event.addListener(_obj,_eventType,function(pt)
    {
        var ptx = pt.latLng.lat();
        var pty = pt.latLng.lng();
        _func.call(this,ptx,pty);
    });
    if(!Cheese(this).buffer("mapEventList"))
    {
        var array = new Array();
        array.push([event,_obj,_eventType]);
        Cheese(this).buffer("mapEventList",array);
    }
    else
    {
        var array = Cheese(this).buffer("mapEventList");
        array.push([event,_obj,_eventType]);
        Cheese(this).buffer("mapEventList",array);
    }
}

CheeseGoogleMap.prototype.removeEvent = function ( _obj , _eventType )
{
    var _map = Cheese(this).buffer("MAPID");
    if(!_map) return;
    if(Cheese(this).buffer("mapEventList") == undefined) return;
    var array = Cheese(this).buffer("mapEventList");
    var tA = new Array();
    var tA2 = new Array();
    var tA3 = new Array();

    for(var i = 0;i<array.length;i++)
    {
        if(array[i][1] == _obj)
            tA2.push(array[i]);
        else
            tA.push(array[i]);
    }
    for(var j = 0;j<tA2.length;j++)
    {
        if(tA2[j][2] = _eventType)
            tA3.push(tA2[j]);
    }
    for(var i = 0;i<tA3.length;i++)
        google.maps.event.removeListener(tA3[i][0]);
    array = tA;
    delete tA2;
    delete tA3;

    Cheese(this).buffer("mapEventList",array);
}

CheeseGoogleMap.prototype.writeMark = function ( _data, _func )
{
    var _map = Cheese(this).buffer("MAPID");
    if(!_map) return;

    var temp = Cheese(this);
    var dataSetCur = _data != undefined ? _data: {};
    Cheese(this).addEvent(Cheese(this).getMap(),"click",function(ptx,pty)
    {
        dataSetCur["image"] != null ? temp.addMarker({"lat" : ptx, "lng" : pty, "image" : dataSetCur["image"]}) : temp.addMarker({"lat" : ptx, "lng" : pty});
        if(_func)  _func.call(this,ptx,pty);
    });
}
CheeseGoogleMap.prototype.writeLine = function ( _data, _func )
{
    var _map = Cheese(this).buffer("MAPID");
    if(!_map) return;

    var thisObj = Cheese(this);
    var dataSetCur = _data != undefined ? _data: {};
    Cheese(this).addEvent(Cheese(this).getMap(),"click",function(ptx,pty)
    {
        if(thisObj.buffer("p1arr") == null)
        {
            var p1arr = new Array();
            var p2arr = new Array();
            p1arr.push(ptx);
            p2arr.push(pty);
            thisObj.buffer("p1arr",p1arr);
            thisObj.buffer("p2arr",p2arr);
        }
        else
        {
            var p1arr =  thisObj.buffer("p1arr");
            var p2arr = thisObj.buffer("p2arr");
            p1arr.push(ptx);
            p2arr.push(pty);
            thisObj.buffer("p1arr",p1arr);
            thisObj.buffer("p2arr",p2arr);
        }
        thisObj.removeLine("str");
        dataSetCur["lat"] = thisObj.buffer("p1arr");
        dataSetCur["lng"] = thisObj.buffer("p2arr");
        dataSetCur["id"] = "str";
        thisObj.addLine(dataSetCur);
        if(_func)  _func.call(this,ptx,pty);
    });
}


CheeseGoogleMap.prototype.data = function ( _data )
{
    var cheeseThis = Cheese(this);

    var dataSetCur = _data;
    cheeseThis.css("width",dataSetCur["width"]);
    cheeseThis.css("height",dataSetCur["height"]);

    var mapId = dataSetCur["mapType"] != null ? google.maps.MapTypeId[dataSetCur["mapType"]] : google.maps.MapTypeId.ROADMAP;
    var Latlng = (!dataSetCur["lat"] && !dataSetCur["lng"]) == true ? new google.maps.LatLng(37.541, 126.986) : new google.maps.LatLng(dataSetCur["lat"], dataSetCur["lng"]);
    var zoom = dataSetCur["zoom"] != null ? dataSetCur["zoom"] : 8;

	var Options = {
		zoom: zoom,
		center: Latlng,
		mapTypeId : mapId,
		mapTypeControl: false,
		navigationControl: dataSetCur["navigationControl"],
		streetViewControl: dataSetCur["streetControl"],
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.DEFAULT,
			position: google.maps.ControlPosition.TOP_RIGHT
		}
	};

    var __map = new google.maps.Map(this, Options);
    cheeseThis.buffer("MAPID",__map);

}













// Cheese BusyIndicator Component
var CheeseBusy = function ( _elementContext )
{
	this.elementContext = _elementContext;
	this.type = "busy";
}

CheeseBusy.prototype.option = function ( _data )
{
	for ( var k in _data)
	{

		if(k == "background"){
			if (_data[k][0] == "color"){
				Cheese(this).parent().parent().css("background",_data[k][1])
			}

			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).parent().parent().css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")")
				} else {
					Cheese(this).parent().parent().addClass("c_"+_data[k][1]);
				}
			}
		}
		if(k == "fontColor"){
			Cheese(this).parent().parent().css("color",_data[k])
		}
		if(k == "borderColor"){
			Cheese(this).parent().parent().css("border-color",_data[k])
		}
		if(k == "fontSize"){
			if (_data[k] == "big"){
				Cheese(this).parent().parent().css("font-size","28px")
			} else if (_data[k] == "normal"){
				Cheese(this).parent().parent().css("font-size","24px")
			} else if (_data[k] == "small"){
				Cheese(this).parent().parent().css("font-size","20px")
			} else {
				Cheese(this).parent().parent().css("font-size",_data[k])
			}
		}
		if(k == "btnAreaBackground"){
			if (_data[k][0] == "color"){
				Cheese(this).find('.popCon .btnArea').css("background",_data[k][1])
			}

			if (_data[k][0] == "gradient"){

				if(_data[k][1].indexOf(" from ") != -1){
					Cheese(this).find('.popCon .btnArea').css("background","-webkit-gradient(linear, 0% 0%, 0% 100%,"+_data[k][1]+")")
				} else {
					Cheese(this).find('.popCon .btnArea').addClass("c_"+_data[k][1]);
				}
			}
		}


		if(k == "indicatorType")
		{
			if (_data[k] == "1"){
				Cheese(this).removeClass().addClass('busyIndicator type1');
			} else if (_data[k] == "2"){
				Cheese(this).removeClass().addClass('busyIndicator type2');
			} else if (_data[k] == "3"){
				Cheese(this).removeClass().addClass('busyIndicator type3');
			}
		}

		if(k == "motionSpeed")
		{
			Cheese(this).css("-webkit-animation-duration",_data[k])
		}
	}

}














// cheese chart part
var CheeseChart = function( _elementContext )
{
    this.elementContext = _elementContext;
    this.type = "chart";
}

//h margin 지정 없앤다. -> 자동으로 계산되어서 그려지도록.
CheeseChart.prototype.data = function ( _data )
{
	var dataSetCur = _data;
	if(!dataSetCur["chartArray"]) return;

	Cheese(this).html('<canvas width="' + Cheese(this).width() + '"' + 'height="'+ Cheese(this).height() +'"/>');

    var property = {};

    // back ground setting & common part setting
    property.data = dataSetCur["chartArray"];
    property.isBorderDelete = dataSetCur["isBorderDelete"] ? dataSetCur["isBorderDelete"] : true;	//h 테두리 없앨지 정하는 변수
    property.tableThickness = dataSetCur["tableThickness"] ? dataSetCur["tableThickness"] : 3;		//h 수직 선, 수평 선 굵기 설정하는 변수
    property.tableOpacity =  dataSetCur["tableOpacity"] ? dataSetCur["tableOpacity"] : 0.5;   		//h 수직 선, 수평 선 투명도 설정하는 변수
    property.tableColor = dataSetCur["tableColor"] ? dataSetCur["tableColor"] : "black";			//h 테두리, 수직 선, 수평 선 색 설정하는 변수

    //h 수직상으로 보이는 택스트 위치 수정 위치와 margin
    //h 얘기해보고 수정하기
    property.verticalTextPosition = dataSetCur["verticalTextPosition"] ? dataSetCur["verticalTextPosition"] : ["left",10];
    //h 수평상으로 보이는 택스트 위치 수정 위치와 margin
    property.horizonTextPosition = dataSetCur["horizonTextPosition"] ? dataSetCur["horizonTextPosition"] : ["top", 10 ];
    //h 수직상으로 보이는 택스트 원하는 택스트로 수정 아닐시에 auto
    property.verticalTextLabels = dataSetCur["verticalTextLabels"] ? dataSetCur["verticalTextLabels"] : [""];
	//h 수평상으로 보이는 택스트 원하는 택스트로 수정 아닐시에 auto
    property.horizonTextLabels = dataSetCur["horizonTextLabels"] ? dataSetCur["horizonTextLabels"] : [""];

	property.verticalMaxValue = dataSetCur["varticalMaxValue"] ? dataSetCur["varticalMaxValue"] : null;
	property.verticalMinValue = dataSetCur["varticalMinValue"] ? dataSetCur["varticalMinValue"] : null;
	property.type = dataSetCur["type"] ? dataSetCur["type"] : "bar";
	property.margin = dataSetCur['margin'] ? dataSetCur['margin'] : 20 ;
	property.horizonLineNum = dataSetCur['horizonLineNum'] ? dataSetCur['horizonLineNum'] :0;
	property.verticalLineNum = dataSetCur['verticalLineNum'] ? dataSetCur['verticalLineNum'] : 0;
	property.backgroundColor = dataSetCur['backgroundColor'] ? dataSetCur['backgroundColor'] : null ;
   	property.chartComponentColors = dataSetCur['chartComponentColors'] ? dataSetCur['chartComponentColors'] : ["blue","red","green"];
	property.isBackgroundVerticalDraw = dataSetCur['isBackgroundVerticalDraw'] ? dataSetCur['isBackgroundVerticalDraw'] : true;
	property.isBackgroundHorizonDraw = dataSetCur['isBackgroundHorizonDraw'] ? dataSetCur['isBackgroundHorizonDraw'] : true;
	property.horizonMargin = dataSetCur['horizonMargin'] ? dataSetCur['horizonMargin'] : 20;
	property.verticalMargin = dataSetCur['verticalMargin'] ? dataSetCur['verticalMargin'] : 20;
	property.lineWidth = dataSetCur['lineWidth'] ? dataSetCur['lineWidth'] : 2;
	property.tableTextSize = dataSetCur['tableTextSize'] ? dataSetCur['tableTextSize'] : 10;
	property.tableTextColor = dataSetCur['tableTextColor'] ? dataSetCur['tableTextColor'] : "black";
	property.tableTextFont = dataSetCur['tableTextFont'] ? dataSetCur['tableTextFont'] : "Verdana";
	property.titleText = dataSetCur['titleText'] ? dataSetCur['titleText'] : "";
	property.titleSize = dataSetCur['titleSize'] ? dataSetCur['titleSize'] : 10;
	property.titleColor = dataSetCur['titleColor'] ? dataSetCur['titleColor'] : "black";
	property.titleFont = dataSetCur['titleFont'] ? dataSetCur['titleFont'] : "Verdana";

	// back draw
	Cheese(this).buffer("CheeseChartComponentDataProperty",property);
	Cheese(this).chartDraw(Cheese(this).width(), Cheese(this).height());
}

CheeseChart.prototype.clicked = function (e)
{

}

CheeseChart.prototype.chartAnimation = function (_data)
{
	var totalCount = parseInt(arguments[2] / 16);
	var width = arguments[0];
	var height = arguments[1];
	var preWidth = parseInt(Cheese(this).css("width"));
	var preHeight = parseInt(Cheese(this).css("height"));
	var func = arguments[3];
	var thisObj = this;
	var value = 0;
	var timer = setInterval(function(){
	Cheese(thisObj).chartDraw(preWidth + (width - preWidth)* value/totalCount, preHeight + (height - preHeight)*value/totalCount)
		if(value == totalCount)
		{
			Cheese(thisObj).chartDraw(width, height);
			if( func )
					func.call(thisObj);
			clearInterval(timer);
		}
		value++;
    },16);
}


CheeseChart.prototype.chartDraw = function( _width, _height )
{
    Cheese(this).css("width",_width + "px")
    Cheese(this).css("height",_height + "px")
	var property = Cheese(this).buffer("CheeseChartComponentDataProperty");
	property.canvas   = Cheese(this).children().dom();
    property.context  = property.canvas.getContext("2d");
    property.canvas.width = _width;
    property.canvas.height = _height;
	var backgroundVerticalSize = (_width - 2 * property.margin) / (property.verticalLineNum + 1);
	var backgroundHorizonSize = (_height - 2 * property.margin) / (property.horizonLineNum + 1);

   	property.context.beginPath();

	var maxValue = 0;
	var minValue = 9999999;
	for(var i = 0;i<property.data.length;i++)
		for(var j = 0;j < property.data[i].length;j++)
		{
			if(property.data[i][j] > maxValue)
				maxValue = property.data[i][j];
			if(property.data[i][j] < minValue)
				minValue = property.data[i][j];
		}

	var max = property.verticalMaxValue ? property.verticalMaxValue : maxValue;
	var min = property.verticalMinValue ? property.verticalMinValue : minValue;
	var height = (_height - 2 * property.margin)
	var width = (_width - 2 * property.margin)

	if(property.backgroundColor != null)
	{
		property.context.fillStyle = property.backgroundColor;
		property.context.fillRect(0, 0 , _width , _height);
		property.context.stroke();
	}
	//h 수평선 긋기

    if (property.isBackgroundHorizonDraw)
	{
		var x = property.margin - property.verticalTextPosition[1];
    	if(property.verticalTextPosition[0] == "right")
			x = _width - property.margin  + property.verticalTextPosition[1];
        for (var i = 0, y = property.margin; i < property.horizonLineNum + 1 ; y += backgroundHorizonSize)
		{
			if(i == 0 )
			{
				i++;
				continue;
			}

			property.context.fillStyle = property.tableColor;
			property.context.globalAlpha = property.tableOpacity;
			property.context.fillRect(property.margin , parseInt( y ) - property.tableThickness/2 ,_width - property.margin*2, property.tableThickness);

			if(property.verticalTextLabels == "auto")
			{
			    var plusValue =  (max  -  min) / (property.horizonLineNum + 1);
			    var result = i * plusValue + min;
                if(result.toString().indexOf(".",0) > 0 )
			    {
			        result = result.toString().slice(0,result.toString().indexOf(".",0) + 3);
			    }

				var textWidth = property.context.measureText(result).width;
				property.context.globalAlpha = 1.0
				property.context.font = property.tableTextSize +'pt '+property.tableTextFont;
				property.context.fillStyle = property.tableTextColor;
				property.context.fillText(result, x , y + property.tableTextSize/2 );
			}
			i++;
        }
    }
    property.context.fillStyle  = "black";
    property.context.globalAlpha = 1.0;

    if(property.verticalTextLabels != "auto")
    {
		var x = property.margin - property.verticalTextPosition[1];
    	if(property.verticalTextPosition[0] == "right")
			x = _width - property.margin + property.verticalTextPosition[1];
        for (var i = 0;i < property.verticalTextLabels.length ;i++ )
		{
			var textWidth = property.context.measureText(property.verticalTextLabels[i]).width;
			var textheight = property.tableTextSize;

			property.context.font = property.tableTextSize +'pt '+ property.tableTextFont;
			property.context.fillStyle = property.tableTextColor;


			if(property.verticalTextLabels.length == 1)
			{
				property.context.fillText(property.verticalTextLabels[i], x , property.margin + height / 2 + textWidth/2);
			}
			else
			{
				property.context.fillText(property.verticalTextLabels[i], x , property.margin + height / (property.verticalTextLabels.length - 1) * i + textheight / 2);
			}
        }
    }
	//h 수직선 긋기
    if (property.isBackgroundVerticalDraw)
	{
		var y = property.margin - property.horizonTextPosition[1];
    	if(property.verticalTextPosition[0] == "bottom")
			y = _height - property.margin + property.horizonTextPosition[1];

        for (var i = 0, x = property.margin; i < property.verticalLineNum + 1; x += backgroundVerticalSize)
		{
			if(i == 0)
			{
				i++;
				continue;
			}
          	property.context.fillStyle = property.tableColor;
			property.context.globalAlpha = property.tableOpacity;
			property.context.fillRect(x - property.tableThickness/2,property.margin , property.tableThickness , height);

			if(property.horizonTextLabels == "auto")
			{
			    var plusValue =  property.data[0].length / (property.verticalLineNum + 1);
			    var result = i * plusValue;
			    if(result.toString().indexOf(".",0) > 0 )
			    {
			        result = result.toString().slice(0,result.toString().indexOf(".",0) + 2);
			    }
				var textWidth= property.context.measureText(result).width;
				property.context.globalAlpha = 1.0
				property.context.font = property.tableTextSize +'pt ' + property.tableTextFont;
				property.context.fillStyle = property.tableTextColor;
				property.context.fillText( result , x - textWidth / 2, y );
			}
			i++;
        }
    }
	property.context.fillStyle  = "black";
	property.context.globalAlpha = 1.0;
	if(property.horizonTextLabels != "auto")
    {
    	var textheight = property.tableTextSize;
		var y = property.margin - property.horizonTextPosition[1];
    	if(property.horizonTextPosition[0] == "bottom")
    		y = _height - property.margin + property.horizonTextPosition[1] + textheight;

        for (var i = 0;i < property.horizonTextLabels.length ;i++ )
		{
			var textWidth= property.context.measureText(property.horizonTextLabels[i]).width;
			property.context.font = property.tableTextSize+'pt '+property.tableTextFont;
			property.context.fillStyle = property.tableTextColor;

			if(property.horizonTextLabels.length == 1)
			{
				property.context.fillText(property.horizonTextLabels[i], property.margin + width / 2 + textWidth / 2, y);
			}
			else
			{
				property.context.fillText(property.horizonTextLabels[i], property.margin + width / (property.horizonTextLabels.length - 1) * i - textWidth/2 , y);
			}
        }
    }
	//h 수직선 라벨 그리기

    if(!property.isBorderDelete)
    {
	    property.context.fillStyle = property.tableColor;
		property.context.strokeRect(property.margin, property.margin, width , height);
		property.context.fillStyle  = "black";
    }

	// title text draw
	property.context.font = 'Bold '+ property.titleSize +'pt '+property.titleFont;
	property.context.fillStyle = property.titleColor;

	var textWidth = property.context.measureText(property.titleText).width/2;
	property.context.fillText(property.titleText, _width - textWidth, property.margin);
   	if(property.type == "bar")
   	{
    	property.context.fillStyle   = property.chartComponentColors[0];
	    property.context.globalAlpha = 1.0;

	    for (var i=0; i<property.data.length; i++)
		{
			var barWidth = (_width - 2 * property.margin) / property.data.length / property.data[0].length;
			var temp = parseInt(barWidth) == 0 ? 1 : parseInt(barWidth)
			for (var j=0; j<property.data[i].length; j++)
			{
				var x = (j * barWidth * property.data.length) + property.margin + i; // 380
				var y = (property.data[i][j] - min) * height / (max - min);

				property.context.beginPath();
	            property.context.fillStyle = property.chartComponentColors[i];
				property.context.fillRect(x , height + property.margin - y, temp , y);
			}
		}
		property.context.closePath();
	}
	else
	{
		for (var i=0;i<property.data.length;i++)
		{
			var x  = 0;
		    var y  = 0;

			property.context.beginPath();
			property.context.strokeStyle = property.chartComponentColors[i];
		    property.context.lineWidth = property.lineWidth;
		    for (var j = 0; j < property.data[i].length; j++)
		    {
		    	x = (j * width / (property.data[i].length - 1)) + property.margin;
				y = height - (property.data[i][j] - min) * height / (max - min) + property.margin;

		        property.context.lineTo(x, y);
		    }
			property.context.stroke();
	    }
	    property.context.closePath();
	}
	Cheese(this).buffer("CheeseChartComponentDataProperty",property);
}
